在C++ struct
中定义方法时,出现“表达式必须具有类类型”错误。我不知道为什么。
编码:
struct qqueue {
int ar[20000];
int rear = 0;
void add_end(int c) {
ar[rear++] = c;
}
void add_front( int c) {
if (rear < ar.sz - 1) { // expression must have class type
for (int i = rear; i > 0; i--)
ar[i] = ar[i - 1];
ar[0] = c;
rear++;
}
else
cout << " is Full";
}
};
最佳答案
ar.sz
不起作用。 ar
类型为int [],没有任何成员。由于您知道编译时的大小,因此可能要写20000。由于您使用的是cpp,因此建议您使用
std::vector
或std::array
关于c++ - C++中的“expression must have class type”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65263717/