C++: Syntax error C2061: Unexpected identifier

后端 未结 5 1493
梦如初夏
梦如初夏 2021-01-06 12:33

What\'s wrong with this line of code?

bar foo(vector ftw);

It produces

error C2061: syntax error: identifier \'vector\'
5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-06 13:20

    Do you have:

    #include

    and

    using namespace std; in your code?

    defines the std::vector class, so you need to include it some where in your file.

    since you're using vector, you need to instruct the compiler that you're going to import the whole std namespace (arguably this is not something you want to do), via using namespace std;

    Otherwise vector should be defined as std::vector

提交回复
热议问题