namespace chk{
class Car;
Car abc()
{
return Car();
}
class Car
{
private:
int sides;
public:
Car()
{
std::cout<<"\ndefault called constructor";
}
Car(int nsides)
{
std::cout<<"\ncalled constructor";
sides=nsides;
}
~Car()
{
std::cout<<"\nDeleting objext";
}
};
/* Car abc()
{
return Car();
}*/
}
我收到上述代码的以下错误:-
check.cpp: In function ‘chk::Car chk::abc()’:
check.cpp:25: error: return type ‘struct chk::Car’ is incomplete
check.cpp:27: error: invalid use of incomplete type ‘struct chk::Car’
check.cpp:24: error: forward declaration of ‘struct chk::Car’
现在,当取消注释下面的 abc() 并在 abc() 上面注释时,它可以正常工作。为什么 c++ 不允许我在命名空间内转发声明类?