dimanche 28 mai 2017

Unable to initialize static vector in c++

I wanted to initialize a vector Stack inside a class as following. That vector will be initialized only once and will not be updated ever.

#ifndef X_HPP
#define X_HPP

#include <vector>

class Test
{
   public:
      void gen(double x);
      void PopStack();

   private:
         static std::vector<double> Stack;
};

#endif

And the CPP file is as follows:

#include "X.hpp"

int main() {
    std::vector<double> Test::Stack = {1,2,3}; 
    Test t;
}

Compiled using the following command:

g++ -std=c++11 Y.cpp

Reported error:

Y.cpp: In function ‘int main()’:
Y.cpp:4:37: error: qualified-id in declaration before ‘=’ token
     std::vector<double> Test::Stack = {1,2,3};

Aucun commentaire:

Enregistrer un commentaire