我是一个班级
class myClass
{
private:
std::list <myInnerClass> mylists;
class myInnerClass
{
// Design for this private class
}
}
我无法理解为什么行std::list <myInnerClass> mylists
会给我以下错误:
- Type 'myInnerClass' was not declared in this scope
- Type 'myInnerClass' could not be resolved
我哪里错了?
答案 0 :(得分:5)
在声明之前使用myInnerClass
。
此代码将编译:
class myClass
{
private:
class myInnerClass
{
// Design for this private class
}
std::list <myInnerClass> mylists;
}
答案 1 :(得分:4)
在宣布它之前,你正在使用你的内部类
修正:
class myInnerClass
{
// Design for this private class
};
std::list <myInnerClass> mylists;
答案 2 :(得分:0)
首先你必须声明内部类然后你可以使用它
您的代码
class myClass
{
private:
std::list <myInnerClass> mylists;
class myInnerClass
{
// Design for this private class
}
}
正确的代码:
class myClass
{
private:
class myInnerClass
{
// Design for this private class
}
std::list <myInnerClass> mylists;
}