摘要:
1 #include 2 using namespace std; 3 int main(int argc, char *argv[]) 4 { 5 cout 2 using namespace std; 3 #include 4 #include 5 int main(int argc, char *argv[]) 6 { 7 ifstream fin("D:\\a.txt"); 8 char ch; 9 while(fin.get(ch))10 {11 cout << ch << flush;12 time... 阅读全文
摘要:
1 #include 2 #include 3 using namespace std; 4 int main(int argc, char *argv[]) 5 { 6 ofstream fout("D:\\a.txt"); 7 fout 2 #include 3 #include 4 using namespace std; 5 6 int main(int argc, char *argv[]) 7 { 8 string stContent = ""; 9 ifstream fin("D:\\a.txt");10 getlin. 阅读全文
摘要:
1 #include 2 using namespace std; 3 4 class Good 5 { 6 public: 7 int member; 8 Good(int a): member(a) 9 {10 cout << "调用构造" << endl;11 cout << "member =" << member << endl;12 }13 void show()14 {15 cout << member << endl;16 }17 18 operator. 阅读全文
摘要:
1 #include 2 using namespace std; 3 4 class Good 5 { 6 public: 7 int member; 8 Good(int a): member(a) 9 {10 cout << "调用构造" << endl;11 cout << "member =" << member;12 }13 void show()14 {15 cout << member << endl;16 }17 Good operator+(const Go... 阅读全文
摘要:
1 #include 2 using namespace std; 3 4 class Good 5 { 6 public: 7 int member; 8 Good(int a): member(a) 9 {10 cout << "调用构造" << endl;11 }12 void show()13 {14 cout << member << endl;15 }16 Good operator+(const Good& obj)17 {18 return Good(m... 阅读全文
摘要:
1 #include 2 using namespace std; 3 4 class Good 5 { 6 public: 7 int member; 8 Good(int a): member(a) 9 {10 cout << "调用构造" << endl;11 }12 void show()13 {14 cout << member << endl;15 }16 Good operator+(const Good& obj)17 {18 return Good(m... 阅读全文
摘要:
1 #include 2 using namespace std; 3 4 class ClassA 5 { 6 int member; 7 8 public: 9 ClassA (int x):member(x)10 {11 cout << ... 阅读全文
摘要:
1 #include 2 using namespace std; 3 4 class ClassA 5 { 6 int member; 7 8 public: 9 ClassA (int x):member(x)10 {11 cout << member <<endl;12 }13 14 friend ClassA Add(const ClassA& a, const ClassA& b);15 };16 17 //习惯使用引用来避免参数复制,提高效率,使用const避免修改 18 ClassA Add(cons... 阅读全文
摘要:
提示,一般不要修改常量的值,没意义!不同的编译器有不同的处理方式。特殊的时候才需要考虑: 1 #include 2 using namespace std; 3 class A{ 4 const int a; 5 public: 6 A(int i):a(i){} 7 const int& geta()const{ 8 return a; 9 }10 };11 int main(){12 //这个可以改13 A a(10);14 cout 2 using namespace std; 3 class B 4 { 5 pub... 阅读全文
摘要:
1 #include 2 using namespace std; 3 class B 4 { 5 public: 6 B() { } 7 public: 8 int m_iNum; 9 };10 void foo()11 {12 const B b1;13 //b1.m_iNum = 100; //compile error14 //上面注释掉的代码编译时会报错,因为b1是一个常量对象,不能对它进行改变;15 // 可以做如下转换,体现出转换为指针类型16 B *b2 = const_cast(&b1);17 // 或者左侧... 阅读全文