jeudi 9 mars 2017

'static_cast' : cannot convert from 'SuperTemplate

If I do the following:

template <typename T>
class SuperTemplate
{
};

enum class MyEnum
{
  Enum1,
  Enum2
};

template<typename T>
SuperTemplate<T> *Func(SuperTemplate<int> *ptr)
{
  std::cout << "Template #1" << std::endl;
  auto newPtr = static_cast<SuperTemplate<T> *>(ptr);
  return newPtr;
}

int main()
{
  auto test = new SuperTemplate<int>();
  auto result = Func<MyEnum>(test);
}

I get the following error:

static_cast' : cannot convert from 'SuperTemplate<int> *' to 'SuperTemplate<MyEnum>

What should I then do to allow such conversion?

Aucun commentaire:

Enregistrer un commentaire