如何访问在另一个类中声明的类? [英] How do I access a class declared inside another class?
本文介绍了如何访问在另一个类中声明的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的课程:
class cup{
public:
cup();
void drinkwater(water *t); // error occurs here
private:
class water{
public:
int litres;
};
};
但是我收到一个错误,说'water'有没有办法访问类,而不必把水类外面?
However I get an error saying that 'water' has not been declared. Is there any way to access the class without having to put the water class outside?
推荐答案
向前声明 class water; 在
drinkwater
的定义之上的私有部分,例如
Forward-declare class water;
in a private section above the definition of drinkwater
, like
class cup{
class water;
public:
cup();
void drinkwater(water *t); // error occurs here
private:
class water{
public:
int litres;
};
};
这篇关于如何访问在另一个类中声明的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文