mardi 24 janvier 2017

Is vector

I have:

#include <cstdlib>
#include <vector>

using namespace std;

int main()
{
   auto a = -SOME_CONST_MAX;
   vector<auto> myVec {a, a, a, a};
}

I don't know the type of the SOME_CONST_MAX but I want to make a vector of the type of -SOME_CONST_MAX. I assumed vector would work as it will deduce from type of a. I'm getting these errors running g++ -std=c++14 main.cpp:

main.cpp:9:9: error: invalid use of ‘auto’
  vector<auto> myVec {a, a, a, a};
         ^
main.cpp:9:13: error: template argument 1 is invalid
  vector<auto> myVec {a, a, a, a};
             ^
main.cpp:9:13: error: template argument 2 is invalid
main.cpp:9:32: error: scalar object ‘myVec’ requires one element in initializer
  vector<auto> myVec {a, a, a, a};
                                ^

Is vector<auto> not allowed ? / What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire