dimanche 22 janvier 2023

c++ initialize vector with pointers to class template

i try to init std vector with pointer to tamplate class
using c++11 and g++
Like this and it fail:

template <typename T>
struct Column  
{
    Column( T data)
    {             
        this->data = data;
    }

    T data;
    
}; 

int main(int argv,char** argc)
{
  std::vector<std::vector<Column*>> csv;
  
}

This i need to i can init Column with diffrent types like this :

 Column<std::string>* tmpString = new Column<std::string>(each);
 csv[0].push_back(tmpString);    

or 

 Column<int>* tmpInt = new Column<int>(each);
 csv[0].push_back(tmpString); 

is there any way to do this ? or maybe better way ?

Aucun commentaire:

Enregistrer un commentaire