using std::vector doesn't work for STL container

Answered

Recently, my distribution of Clion (2017.2) seems unable to handle using std::vector properly. As shown in the following example, it always tell me there is a "too few template arguments, expected 2" error at a vector object declaration. However, it always compiles and runs without any problem.

#include <iostream>
#include <vector>

using std::vector;
using std::cout;
using std::endl;

int main() {
cout << "Hello, World!" << endl;
vector<int> a; //error here under int
a.push_back(5);
cout<<a[0]<<endl;
return 0;
}

The following cmake file is used for the example.

cmake_minimum_required(VERSION 3.8)
project(untitled)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})

The error disappears if I change using std::vector to using namespace std or move using std::vector into the function definition. It also happens when I use other STL containers, e.g. deque. It seems related to the default allocator.

Did I use the "using-declearation" incorrectly? Is there anything I should configure to make it work properly?

Thanks

 

3
2 comments

Having exactly the same problem.

0

Hi all!

We already have the issue in out tracker. Please feel free to comment or upvote. Sorry for the inconvenience! 

0

Please sign in to leave a comment.