は何がやりたいことはnartually C++でサポートされていない:あなたが持つことができません半分のデフォルトコンストラクタ。
しかし、あなたが達成したいが、以下の小さなトリックで行うことができます。
以下この小さなデモを注意してください多くの欠陥(メモリリークなど)を持っているので、それだけでdemostrationのためにのみ暫定ソリューションです。
//class A hasa large number date members(but all can take advantage of default
//copy constructor
struct A{
A(int i):a(i){}
int a;
//much more data memberS can use default copy constructor all in class A
};
//class B is simply wrapper for class A
//so class B can use the default constructor of A
//while just write copy constructor for a raw pointer in it's copy constructor
//I think this is what OP want ?
struct B
{
B(int i,int j):m_a(i),m_b(new int(j)){}
B(const B & rval):
m_a(rval.m_a),
m_b(new int(*rval.m_b))
{
}
A m_a;
int * m_b;
};
int main()
{
B c(2,3); // a=2, *m_b=3
B d(c); //after copy constructor, a=2, *m_b=3
}
このデフォルトのコピーコンストラクタは簡単ではありません – Benoit
なぜこれが必要ですか?あなたはクラスを変更できませんか? –
ちょうど私はそれのためのコピーコンストラクタを書く必要があるので、私はちょうど単一のポインタ(と私はスマートポインタを使用することはできません)とかなり大きいクラスがありますが、コピーコンストラクタのほとんどは、どちらかというと –