03 2014 档案

摘要: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. 阅读全文
posted @ 2014-03-26 23:02 秋月的私语 阅读(213) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2014-03-26 22:54 秋月的私语 阅读(232) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2014-03-26 22:01 秋月的私语 阅读(214) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2014-03-25 21:13 秋月的私语 阅读(200) 评论(0) 推荐(0) 编辑
摘要: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 << ... 阅读全文
posted @ 2014-03-22 21:23 秋月的私语 阅读(225) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2014-03-20 22:03 秋月的私语 阅读(430) 评论(0) 推荐(0) 编辑
摘要:提示,一般不要修改常量的值,没意义!不同的编译器有不同的处理方式。特殊的时候才需要考虑: 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... 阅读全文
posted @ 2014-03-19 21:38 秋月的私语 阅读(1402) 评论(0) 推荐(0) 编辑
摘要: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 // 或者左侧... 阅读全文
posted @ 2014-03-17 22:57 秋月的私语 阅读(151) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 using namespace std; 3 4 class MyClass1 5 { 6 public: 7 int a; 8 void Show(bool bSwitch) const //对应const 类 ,注意const的位置 9 {10 cout a = a;16 }17 private:18 int b; 19 };20 21 class MyClass2 : public MyClass122 {23 public:2... 阅读全文
posted @ 2014-03-09 00:28 秋月的私语 阅读(232) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 using namespace std; 3 4 class MyClass1 5 { 6 public: 7 int a; 8 void Show(bool bSwitch) 9 {10 cout << "a=" << a << endl;11 }12 private:13 int b; 14 };15 16 class MyClass2 : public MyClass117 {18 public:19 int c;... 阅读全文
posted @ 2014-03-07 21:37 秋月的私语 阅读(1285) 评论(0) 推荐(0) 编辑
摘要:1 #include 2 using namespace std; 3 class Test1 4 { 5 public: 6 int m; 7 Test1(int n) { num = n; } //普通构造函数 8 void Show() 9 {10 cout << "private num = " << num <<endl;11 }12 private:13 int count;14 int num;15 int n;16 };17 class Test218 {19 public:20 exp... 阅读全文
posted @ 2014-03-04 20:27 秋月的私语 阅读(299) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示