gpt4 book ai didi

c++ - 具有 vector 成员的全局结构

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:59:37 26 4
gpt4 key购买 nike

<分区>

为什么这个简单的代码块不能编译

//using namespace std;
struct test {
std::vector<int> vec;
};
test mytest;

void foo {
mytest.vec.push_back(3);
}

int main(int argc, char** argv) {
cout << "Vector Element" << mytest.vec[0] << endl;
return 0;
}

我收到以下错误:

vectorScope.cpp:6:5: error: ‘vector’ in namespace ‘std’ does not name a type

vectorScope.cpp:11:6: error: variable or field ‘foo’ declared void

vectorScope.cpp:11:6: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x [enabled by default]

vectorScope.cpp:12:12: error: ‘struct test’ has no member named ‘vec’

vectorScope.cpp:12:28: error: expected ‘}’ before ‘;’ token

vectorScope.cpp:13:1: error: expected declaration before ‘}’ token

谢谢,

穆斯塔法

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com