相关讨论
[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 " 在一个帖子说“ 访问权限是是限制“类”...
派生类会从其基类没有选择的接收所有成员(除构造和析构函数),这是谭浩强的话,对吗?
-----------------------------------------------------
书上这样说的,是他的c++教材,但是我不能理解,
因为基类的私有成员,派生类是不会接收的呀。为什么他会这样讲呢?
私有成员,不会被继承,我的理解对吗?
随手写了这么个程序,请朋友们指点一下:
[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派生出来的——的成员函...
我在一个类里想访问另一个类的一个私有函数,有什么方法吗?
#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()"<
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,还有没有其它的呢?谁知道请贴上来。
#include
class A
{
public:
A()
{
printf("a construct\n");
}
void virtual Display()
&n...