有关C++中嵌套类的一个有关问题
有关C++中嵌套类的一个问题
我在看 The C++ Programming Language 一书, 在11章实现String类时遇到一个关于嵌
套类的问题. 如下:
class String
{
public:
37行 Cref operator[](int i)
38行 {
check(i);
return Cref(*this, i);
}
public:
clss Cref
{
这里是class Cref的定义
};
}
在VS2005下编译总是报错:
错误 1 error C2143: syntax error : missing '; ' before '[ '
d:\codes\final\ch11_2\ch11_2\ch11_2.h 37
错误 2 error C4430: missing type specifier - int assumed. Note: C++
does not support default-int d:\codes\final\ch11_2\ch11_2\ch11_2.h 37
错误 3 error C4430: missing type specifier - int assumed. Note: C++
does not support default-int d:\codes\final\ch11_2\ch11_2\ch11_2.h 38
不知道我将问题描述清楚了没有,请问大家,这个问题应该怎么解决呢?
------解决方案--------------------
class Cref定义要放到operator[]前面
我在看 The C++ Programming Language 一书, 在11章实现String类时遇到一个关于嵌
套类的问题. 如下:
class String
{
public:
37行 Cref operator[](int i)
38行 {
check(i);
return Cref(*this, i);
}
public:
clss Cref
{
这里是class Cref的定义
};
}
在VS2005下编译总是报错:
错误 1 error C2143: syntax error : missing '; ' before '[ '
d:\codes\final\ch11_2\ch11_2\ch11_2.h 37
错误 2 error C4430: missing type specifier - int assumed. Note: C++
does not support default-int d:\codes\final\ch11_2\ch11_2\ch11_2.h 37
错误 3 error C4430: missing type specifier - int assumed. Note: C++
does not support default-int d:\codes\final\ch11_2\ch11_2\ch11_2.h 38
不知道我将问题描述清楚了没有,请问大家,这个问题应该怎么解决呢?
------解决方案--------------------
class Cref定义要放到operator[]前面