C++
windtakers
这个作者很懒,什么都没留下…
展开
-
c++ vector
https://en.cppreference.com/w/cpp/container/vector#include <iostream>#include <vector> int main(){ // Create a vector containing integers std::vector<int> v = {7, 5, 16, 8}; // Add two more integers to vector v.原创 2020-10-14 14:49:10 · 121 阅读 · 0 评论 -
int or unsigned int
int 声明的变量默认是signed int 带符号的,如果需要无符号整型,必须明确声明 unsigned int.#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]) { int i = 2147483645; int j = 2147483649; ...原创 2013-10-31 08:45:47 · 826 阅读 · 0 评论 -
C++ 运行时绑定
C++ 动态绑定C++ 的虚函数 + 派生类对象及派生类到基类的类型转换 共同完成了C++ 面向对象程序设计的三个基本概念之一--动态绑定。同样一段代码运行时才能决定运行的具体函数是哪个(相对于编译时就能确定而言),这个概念在C++ 中称为动态绑定或运行时绑定(run-time binding)。例如,定义下面一个接口用于打印书籍的总价格,这个接口既可以用于打印没有折扣的书籍价格(基类原创 2013-11-05 09:38:57 · 2081 阅读 · 0 评论 -
C++ 构造函数
C++ 构造函数C++ 中定义全局的对象,会引发该对象对应类及其父类的构造函数执行,因此可先于main() 函数执行。如:#include using namespace std;// Base class definationclass Quote {public: Quote() = default; Quote(const std::string &bo原创 2013-11-05 10:11:58 · 652 阅读 · 0 评论 -
C++ 纯虚函数
纯虚函数:和普通的虚函数不一样,纯虚函数无需定义。通过在函数体的位置书写 =0 就可以将一个虚函数声明为纯虚函数。含有纯虚函数的类是抽象类(abstract base class)。抽象类负责定义接口,后续的其他类可以覆盖该接口。C++ 不允许创建一个抽象类的对象。看个例子://==================================================原创 2013-11-04 16:58:19 · 1495 阅读 · 0 评论 -
C/C++ 二维数组、多维数组
严格来说,C/C++ 语言中并没有多维数组,通常所说的多维数组其实就是数组的数组。对于二维数组来说,常把第一个维度称作行,第二个维度称作列。看个例子,重点看下二维数组在内存中的存储:/* ============================================================================ Name : two-d原创 2013-10-14 13:37:57 · 928 阅读 · 0 评论 -
< C++ > string c_str
c_str() 以const char* 类型返回 string 内含的字符串如果一个函数要求char*参数,可以使用c_str()方法:string s = "Hello World!";printf("%s", s.c_str()); //输出 "Hello World!"原创 2013-09-09 15:08:19 · 732 阅读 · 0 评论 -
< C++ > initializer list 初始化列表(构造函数后面加个冒号的解释)
http://zhidao.baidu.com/link?url=N96OhNn11PxhkTNk7SCmd-2g3nrmKv-CtfjMKObGWo15eurHVS9Un03jwkP5BC5xErOXpTbgVHmEL3GBsV_8s_http://zhidao.baidu.com/link?url=KkbSv_fAwmR-RVvp8KfZQyxyPaG4PlHKmLyTNpabEV82bX原创 2013-09-09 14:26:52 · 2112 阅读 · 0 评论 -
< C++ > Default Arguments
摘自 C++ primer 5th edition:Let’s look at another topic from C++’s bag of new tricks: the default argument. A default argu-ment is a value that’s used automatically if you omit the corresponding act原创 2013-09-09 13:32:16 · 1991 阅读 · 0 评论