【发布时间】:2021-03-04 04:22:06
【问题描述】:
这是我在使用 std::vector 和 MSVC 时遇到的问题的最小可重现示例
#include <iostream>
#include <vector>
#include <string>
using namespace std; // For brevity
struct Struct
{
vector< int > Values(6, 0); // Should hold 6 zeros
vector< int > NormalConstructor; // Example of normal vector
void Dump() { for (auto val : Values) { cout << val << " "; } }
};
int main()
{
Struct s;
s.Dump();
cout << "\n";
}
vector< int > Values(6, 0); 行的结果是error C2059: syntax error : 'constant',名为Value 的变量被着色,就好像它是一个函数声明一样。
cppreference.com 说这个构造函数 “3) 构造具有值 value 元素的 count 个副本的容器”
这里有几个问题,我看过这些问题,但似乎没有一个表明出了什么问题,或者我应该做些什么来避免这个错误。
我应该怎么做?
【问题讨论】:
标签: c++ visual-studio stdvector