随笔分类 - C++
摘要://Author: Yao H. Wang//转载请注明出处:http://www.cnblogs.com/yaohwang/archive/2012/03/04/2367987.html 测试代码如下: 1 #include "stdafx.h" 2 #include <iostream> 3 4 using namespace std; 5 6 class Base 7 { 8 public: 9 int pubi;10 void pub()11 {12 cout << "Base public" << endl;
阅读全文
摘要://Author: Yao H. Wang//转载请注明出处:http://www.cnblogs.com/yaohwang/archive/2012/03/03/2367983.html Const成员如其它任何成员一样,简单考虑其出现在三个位置:全局作用域、普通函数内部、类里面。下面请看测试代码: 1 #include "stdafx.h" 2 #include <iostream> 3 4 using namespace std; 5 6 class A 7 { 8 public: 9 const int j;10 //const int k = 3;11
阅读全文
摘要:请先看测试代码: 1 #include "stdafx.h" 2 #include <iostream> 3 4 using namespace std; 5 6 //基类 7 class Base 8 { 9 public:10 void get() const;11 private:12 virtual void dosth() const;13 };14 15 void Base::get() const16 {17 dosth();18 }19 20 void Base::dosth() const21 {22 cout << "B
阅读全文
摘要:using声明,形式如下:using 作用域名::名字还是先举个例子: 1 class Base 2 { 3 public: 4 int pubi; 5 void pub() 6 { 7 }; 8 }; 9 10 class Derived1:public Base11 {12 public:13 using Base::pub;14 };其中 的using Base::pub就是using声明。下面再来看看测试代码: 1 #include "stdafx.h" 2 #include <iostream> 3 4 using namespace std...
阅读全文
摘要:首先介绍一下概念,我所说的类中的访问标号,如下例:class Base
{
public: protected: private: };其中的public、protected、private即为“类中的访问控制标号”。派生标号呢?也举一例:class Derived1: public Base
{ };其中的public即为“派生访问标号”,当然也有相应的protected、private。1、public派生不改变基类中的成员和方法在派生类中的“类中的访问控制标号”。2、protected将原来基类中的public成员和方法在派生类中的“类中的访问控制标号”变为protected。3...
阅读全文
浙公网安备 33010602011771号