[英]Two classes with member functions taking a pointer to an object from the other class
class a {
public:
void f2(b * elem);
};
class b {
public:
void f1(a * elem);
};
這里會有問題。
void f2(b * elem);
如何以可以使用函數f2
的方式聲明類b
?
告訴編譯器有一個類a和b。 但是不要告訴他/她它們的外觀:)可能是因為您使用了指針。 對於編譯器來說,它只是一個整數。 稍后,您可以定義類的所有功能,現在編譯將很高興知道它們的外觀。
class a; // tell the compiler there is a class a
class b; // tell the compiler there is a class b
// real implementation of class a
class a {
public:
void f2(b * elem);
};
// real implementation of class b
class b {
public:
void f1(a * elem);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.