回复 19楼 Devil_W
怎么不可以了,上面的私有的。子类不可以访问。
而父类通过STATIC 来进行构造。
那里不可以了,,,

用心做一件事情就这么简单
2012-02-25 11:23
程序代码:#include "StdAfx.h"
#include <iostream>
using namespace std;
class A
{
public:
static A* f()
{
return new A;
}
private:
A()
{
cout<<"construct"<<endl;
}
};
class B:public A
{
public:
B()
{
cout<<"B constrcut"<<endl;
}
};
int main()
{
cout << "Hello world!" << endl;
//A d(0,0);
A *a = A::f();
//B c;
return 0;
}这样可以实现符合你的要求了吧。。。。
2012-02-25 22:07
程序代码:#include <iostream>
using namespace std;
class A
{
public:
static A* f()
{
return new A;
}
private:
A()
{
cout<<"construct"<<endl;
}
};
class B:public A
{
public:
B():A(*A::f())
{
cout<<"B constrcut"<<endl;
}
};
int main()
{
cout << "Hello world!" << endl;
B b();
return 0;
}
2012-02-26 11:46
程序代码:#include <iostream>
using namespace std;
class A
{
public:
static A* f()
{
return new A;
}
private:
A()
{
cout<<"construct"<<endl;
}
A(A&)
{
cout<<"不给你调用复制构造函数"<<endl;
}
};
class B:public A
{
public:
B():A(*A::f())
{
cout<<"B constrcut"<<endl;
}
void print()
{
cout<<"nihao"<<endl;
}
};
int main()
{
cout << "Hello world!" << endl;
B b;
b.print();
return 0;
}
2012-02-26 12:00
2012-02-26 13:03