摘要:代码: 会调用参数为int && 的[]重载函数,也就是 注意此函数不能返回const int&,因为不能给一个const赋值。 这句话的含义是 先t[1],然后赋值i
阅读全文
随笔分类 - c++
摘要:代码: 会调用参数为int && 的[]重载函数,也就是 注意此函数不能返回const int&,因为不能给一个const赋值。 这句话的含义是 先t[1],然后赋值i
阅读全文
摘要:隐式转换 在赋值给一个兼容类型会出现隐式类型转换.比如下面这个例子. 在以上例子中.值从short自动提升到int,这是标准转换。标准转换影响基本数据类型,它在类型数字类型之间(short to int, int to float, double to int...), 布尔类型和一些指针之间执行。
阅读全文
摘要:不会用就直接复制粘贴
阅读全文
摘要:原文地址:https://en.cppreference.com/w/cpp/container/map/map
阅读全文
摘要:#include #include #include #include #include using namespace std; int main() { //freopen("d://1.text", "r", stdin); map *maps = new map(); maps->insert(pair(0, "0")); maps->i...
阅读全文
摘要:输出 for end //循环结束输出delete //删除pp对象main end //main函数结束 //下面是5个delete 和 const int NN=5对应 delete deletedeletedeletedelete //所以, delete 0 永远都是安全的 //注意前面有个
阅读全文
摘要:#include using namespace std; class Example5 { string* ptr; public: Example5(const string& str):ptr(new string(str)){} ~Example5(){delete ptr;} //copy constructo...
阅读全文
摘要:#include using namespace std; class MyClass { public: int x; static int n; const int y; MyClass(int val) : x(val), y(20) { } // ...
阅读全文
摘要:#include using namespace std; class Dummy { public: static int n; int x; Dummy() : x(0) { n++; } Dummy(int xx) ...
阅读全文
摘要:#include using namespace std; class Dummy { public: int x; Dummy() : x(0) { } ; Dummy(int xx) : x(xx) { } ; bool isitem(Dummy const&)...
阅读全文
摘要:#include using namespace std; class CVector { public: int x, y; CVector() : x(0), y(0) { } CVector(int a, int b) : x(a), y(b) { } ; CVect...
阅读全文
摘要:#include using namespace std; class Circle { double radius; public: Circle(double r) { radius = r; } double area() { return 2 * radius; } }; class Cylind...
阅读全文
摘要:#include #include #include using namespace std; /** * url:http://www.cplusplus.com/doc/tutorial/other_data_types/ */ /** * in which all its member elements occupy the same physical space in memor...
阅读全文
摘要:#include #include using namespace std; int main() { /** * 动态内存 * url: http://www.cplusplus.com/doc/tutorial/dynamic/ * 关键字new用于在程序运行时动态开辟内存,内存开辟在堆空间. * 此关键字不保证内存一定开辟成功,如果开辟...
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include #include using namespace std; /** * 命名空间 * *namespace identifier *{ * named_entities *} */ nam...
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include #include using namespace std; /** * 重载,函数有不同数目的参数或者是不同类型的参数 */ int operate(int a, int b) { return (...
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include #include using namespace std; /** * Calling a function with parameters taken by value causes copies o...
阅读全文
摘要:来自官方文档。。。感谢老王指出需要c++11,一下代码全在c++11下编译,编译参数加入 -std=c++11
阅读全文
|