I'm extending a base template class that provides a template method (that I cannot change). I can instantiate the class, but I cannot use the instatiation of the template method. The compiler is not getting at all what I'm trying to do, and when I try to compile I get syntax error about the template part. Do you know how should I do that? The following code synthesize the same situation.
#include <iostream>
namespace MyNameSpace
{
template<class T, class U>
class BaseTemplateClass
{
public:
explicit BaseTemplateClass(T t, U u): paramT{t}, paramU{u}
{
std::cout << "BaseConstructor" << std::endl;
}
template<typename Z>
Z Get()
{
std::cout << "Call to Get()" << std::endl;
return Z{};
}
private:
T paramT;
U paramU;
};
}
template<class V, class W>
class DerivedTemplateClass : public MyNameSpace::BaseTemplateClass<V, double>
{
using Base = MyNameSpace::BaseTemplateClass<V, double>;
public:
DerivedTemplateClass(V t, double u, W w): Base(t, u), paramW{w}
{
std::cout << "DerivedConstructor" << std::endl;
}
void DoSomething()
{
int something = Base::Get<int>();
}
private:
W paramW;
};
using DerivedClass = DerivedTemplateClass<int, bool>;
DerivedClass instance{3, 4.2, true};
To complicated things more, I would also have to instantiate a variable like that:
typename V::InternalType something = Base::Get<V>();
Thanks for the help :)
error: expected primary-expression before 'int'
int something = Base::Get(); ^~~ myfile.h:197:35: error: expected ',' or ';' before 'int'