摘要:
代码1: #include <iostream> using namespace std; class Person { public: int id = 200; //如果这里没有代码id(1000),定义出来的对象的id值为int id = 200;代码初始的值 Person() : id(10 阅读全文
posted @ 2021-11-07 16:15
邱明成
阅读(110)
评论(0)
推荐(0)
摘要:
#include <iostream> using namespace std; class Person { public: int id = 200; string name = "qiumc"; // 在类中声明并定义静态常量字符串数组 // char*改为string类型会报错 // 没有c 阅读全文
posted @ 2021-11-07 15:36
邱明成
阅读(1752)
评论(0)
推荐(1)
摘要:
a1.cpp代码: static int TEST_COMMON = 100; a2.cpp代码: #include <iostream> using namespace std; extern int TEST_COMMON; int main(int argc, char const *argv 阅读全文
posted @ 2021-11-07 14:53
邱明成
阅读(267)
评论(0)
推荐(0)
摘要:
#include <iostream> using namespace std; int& GetStaticVar() { static int a = 100; a++; return a; } int main(int argc, char const* argv[]) { cout << G 阅读全文
posted @ 2021-11-07 14:24
邱明成
阅读(606)
评论(1)
推荐(0)
摘要:
一:知识点: 成员函数末尾增加const1)该函数被称为常量成员函数2)在函数的定义和声明处的末尾都要加const3)该成员函数不能修改类中的任何成员(非mutable修饰的任意成员属性)4)const 类型的类变量,不能调用非常量成员函数5)const和非const类变量,可以调用常量成员函数(c 阅读全文
posted @ 2021-11-07 11:33
邱明成
阅读(205)
评论(0)
推荐(0)
摘要:
#include <iostream> #include <string> using namespace std; class Person { public: int id; string name; public: Person() { this->id = 200; cout << "Non 阅读全文
posted @ 2021-11-07 10:10
邱明成
阅读(178)
评论(0)
推荐(0)