唯一のコンストラクターが整数を受け入れるクラスがあり、それをポインターにせずに新しい/削除を使用せずに別のクラスで使用したいと考えています。
これは可能ですか?
ファーストクラスの関連部分:
class A
{
private:
int size;
char *c;
public:
A(int i)
{
size = i;
c = new char[i];
}
~A() { delete[] c; }
}
そして、次のようにクラス B の例で使用したいと思います。
class B
{
private:
A a(7); // Declaration attempt #1
A b; //Declaration attempt #2
A *c; //This is what I'll do if I have no other choice.
public:
B()
{
b = A(7); //Declaration attempt #2
c = new A(7);
}
}