どして
class A;
template<typename T> class B
{
private:
A* a;
public:
B();
};
class A : public B<int>
{
private:
friend B<int>::B<int>();
int x;
};
template<typename T>
B<T>::B()
{
a = new A;
a->x = 5;
}
int main() { return 0; }
結果
../src/main.cpp:15:エラー:テンプレートとしてのコンストラクターの無効な使用
../src/main.cpp:15:注:「B::classB」の代わりに「B::B」を使用してコンストラクターに修飾名を付けます
まだ結果にfriend B<int>::B<int>()
変更friend B<int>::B()
../src/main.cpp:15:エラー:いいえ'void B :: B()'クラス'B'で宣言されたメンバー関数</p>
テンプレートを完全に削除しながら
class A;
class B
{
private:
A* a;
public:
B();
};
class A : public B
{
private:
friend B::B();
int x;
};
B::B()
{
a = new A;
a->x = 5;
}
int main() { return 0; }
コンパイルと実行は問題なく実行されます-私のIDEが友人B::B()は無効な構文であると言っているにもかかわらず?