I'm trying to initialize a vector with an explicit allocator, but the code below seems not working:
vector<int> a1(allocator<int>()); cout << a1.size(); //Error C2228: left of '.size' must have class/struct/union There is also a working version:
vector<int> a2(*(new allocator<int>())); cout << a2.size(); // OK And another:
vector<int> a3(a2, allocator<int>()); cout << a3,size(); // OK I want to know why only the first version is not working. I'm using MSVC with C++17, and it seems the compiler won't regard a1 as an object. Thanks.
a1is a function declaration. You fell victim to the most vexing parse.