如何解决"class must be used when declaring a friend"错误?
How to resolve "class must be used when declaring a friend" error?
class two;
class one
{
int a;
public:
one()
{
a = 8;
}
friend two;
};
class two
{
public:
two() { }
two(one i)
{
cout << i.a;
}
};
int main()
{
one o;
two t(o);
getch();
}
我从dev - c++得到这个错误:
a class-key must be used when declaring a friend
但在Microsoft Visual c++编译器下运行良好
你需要
friend class two;
代替
friend two;
同样,您不需要单独向前声明您的类,因为朋友声明本身就是一个声明。你甚至可以这样做:
//no forward-declaration of two
class one
{
friend class two;
two* mem;
};
class two{};
你的代码有:
friend two;
应该是:
friend class two;
相关文章:
- 调试控制台 ChessEngine.exe "used"在另一个应用程序(国际象棋 GUI)中
- C++ - 在我尝试制作一个简单的计算器时有一个"uninitialized local variable y used"警告
- SFINAE:"enable_if cannot be used to disable this declaration"
- 行 - " vector<int> used(adj.size(), 0); "是什么意思?
- 如何理解"abstract-declarator containing an ellipsis shall only be used in a parameter-declaration"
- WaitForMultipleObjects when bwaitall is false
- E_INVALIDARG when calling CreateGraphicsPipelineState
- 警告的原因是什么:"when type is in parentheses, array cannot have dynamic size"?
- 解决方法:'can not be used when making a shared object; recompile with -fPIC'使用Cmake。使用普通的 g++ 工作
- 60603 (Fedora Cygwin 5.4.0-2) when using std::cout
- С 错误"s1, s2 are used uninitialised in this function"
- "expression cannot be used as a function"回报声明
- 为什么这句话"The expression can be used only as the left-hand operand of a member function call"在 [expr.re
- 递增变量"never used" ?
- 虽然循环错误:"Uninitialized local variable used"
- cc.game.restart() carsh when extend sdkbox in cocos2d-js 3.1
- "Variable Array set but not used"
- 链接错误:"relocation R_X86_64_32 ... can not be used when making a shared object; recompile with -fPIC"
- 如何解决"class must be used when declaring a friend"错误?
- 为什么" 'static' may not be used when defining (as opposed to declaring) a static data member"?