小编dag*_*i12的帖子

类中的向量(没有类类型)

我在课堂上遇到了一些麻烦.

#include <vector>
using namespace std;

class sth {
    vector<int> tab();
    public:
        void add(int i);
};

void sth::add(int i){
    tab.push_back(i);
}

int main() {
    sth a;
    a.add(10);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个简单的代码导致11 5 [Error] '((sth*)this)->sth::tab' does not have class type 任何想法发生了什么?

c++ class vector

1
推荐指数
1
解决办法
1898
查看次数

标签 统计

c++ ×1

class ×1

vector ×1