ChinaUnix.net
相关文章推荐:

C 派生类成员访问权限

Bjarne Stroustrup著 裘宗燕译 C++程序设计语言(特别版) Page373/374 从书上理解:可以安全地将一个指向基类成员的指针赋值给一个指向派生类成员 的指针,反过来不行。 另外,可将一个指向派生类对象的指针赋值给一个指向基类得指针, 即基类指针可在不加显式转换的情况下指向派生类对象。 不懂的地方:上述两个规则都是为了维护一种基本保证:如果一个对象所提供的性 质少于...

by cinhwa - C/C++ - 2009-05-12 16:45:01 阅读(4921) 回复(4)

相关讨论

[code] template class test { private: T value; public: test() {} test(const test &ref) : value(ref.value) {} //1 没问题 template test(const test &r) : value(r.value) {} //2 编译会有问题!! }; [/code] 1 和2 同样为复制构造函数,如果将其定义为成员模版(例如2 所示),将会编译出错,而1 没问题。 我记得 " OwnWaterloo " 在一个帖子说“ 访问权限是是限制“类”...

by disheng727 - C/C++ - 2009-05-23 23:56:08 阅读(965) 回复(4)

派生类会从其基类没有选择的接收所有成员(除构造和析构函数),这是谭浩强的话,对吗? ----------------------------------------------------- 书上这样说的,是他的c++教材,但是我不能理解, 因为基类的私有成员派生类是不会接收的呀。为什么他会这样讲呢? 私有成员,不会被继承,我的理解对吗?

by go_hao - C/C++ - 2009-10-14 10:52:51 阅读(969) 回复(3)

随手写了这么个程序,请朋友们指点一下: [code] #include; #include; using namespace std; class A { public: void f(){cout<<"这是classA的成员函数"<成员函数";} private: int b; }; class C:public B { public: void f(){cout<<"这是classC——它是classB派生出来的——的成员函...

by albcamus - C/C++ - 2004-06-18 21:36:15 阅读(1212) 回复(4)

我在一个类里想访问另一个类的一个私有函数,有什么方法吗?

by sdemon915 - Java - 2005-10-23 20:13:10 阅读(1628) 回复(9)

#include ; class B1 { public: B1(int i){cout << "constructing B1" << i << endl;} }; class B2 { public: B2(int j){cout << "constructing B2" << j << endl;} }; class B3 { public: B3(){cout << "constructing B3" << * << endl;} }; class C:public B2,public B1,public B3 { public: C(int a,int b,int c,int d):B1(a),memberB2(d),memberB1(c),B2(b){} ...

by 摘仙龙 - C/C++ - 2004-04-18 08:27:25 阅读(1368) 回复(3)

#include typedef struct { int a; int b; int d; int e; }C; int main(){ C c={10,8,2,4}; C *p=&c; printf("%d,%d,%d,%d\n",*p,&p,&p+1,&p+2);谁可以从原理上解释一下这一句 printf("%d,%d,%d,%d\n",*p); printf("%d,%d,%d,%d\n",p,&p,&p+1,&p+2); r...

by xxldc - C/C++ - 2007-09-26 16:42:06 阅读(6352) 回复(31)

[code]#include using namespace std; class A { public: A() { cout<<"A()"<

by kewenliang - C/C++ - 2008-09-23 20:17:10 阅读(2749) 回复(15)

class MyString {  private:   const char * c_string_;   const MyString& operator=(const MyString& rhs);  public:   // Clones a 0-terminated C string, allocating memory using new.   static const char * CloneCString(const char * c_string);   ////////////////////////////////////////////////////////////   //   // C'to...

by aaaaal - C/C++ - 2009-07-28 23:43:59 阅读(1992) 回复(11)

用::直接访问类的成员类型比较少,我想总结一下,我只知道用类名加::可以访问 public的static成员函数和public的enum,还有没有其它的呢?谁知道请贴上来。

by beginer1 - C/C++ - 2005-03-07 23:18:16 阅读(432) 回复(1)

#include class A { public:         A()         {                 printf("a construct\n");         }         void virtual Display()    &n...

by happytor - C/C++ - 2008-11-12 17:57:42 阅读(1431) 回复(7)