mercredi 21 décembre 2016

Template declaration inside if statement [duplicate]

This question already has an answer here:

I'm trying to understand the C++ template. I'm not too much expert in programming so sorry if I'm saying or writing something stupid. I have the following Template

template <class C> class A
{
   public:
   A(){};
   // some functions here
}

In my main function I want something as

int a;

// a function that evaluates if a must be set to 1 or 0

if(a==1)
{
  A  var<Class1>();
}else{
  A  var<Class2>();
}

I know that this is not possible to do, but I'm asking how can I achieve something like this.

Aucun commentaire:

Enregistrer un commentaire