c++ - C++中的“expression must have class type”错误

标签 c++ arrays struct syntax-error

在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::vectorstd::array

关于c++ - C++中的“expression must have class type”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65263717/

相关文章:

java - 我声明的数组大小是否与我的搜索有关?

ios - 更改 NSHomeDirectory 中文件的名称

c - 使用 fwrite() 将结构写入文件

c - 打印链接结构的停止条件?

struct - 如何在 D 中初始化全局结构数组?

c++ - 用 gcc 编译 std::regex_iterator

c++ - 视频的持续时间 (OpenCV)

ios - 如何在 Swift 中解析具有多个数组的 JSON

c++ - 涉及类的突变困难

c++ - WinDivert - 修改数据包数据/负载内容