template <class T>
class Test{
public:
Test(T){ }
template <class U>
U to() const{ return U(0); }
};
template <class Real>
class Base{
typedef Test<Real> TST;
protected:
Base(const TST& t){
_i = t.to<int>(); // <- but this gives error
}
int _i;
};
template <class Real, class T> class Child;
template <class Real>
class Child<Real, int> : public Base<Real>{
typedef Base<Real> F;
typedef Test<Real> TST;
public:
Child() : F(TST(23.0)){ }
};
int main(int argc, char* argv[]){
Child<double, int> rw;
Test<double> t1(3.3);
int i = t1.to<int>(); // <- this works
return 0;
}
Вызов to
в основном работает, но я не могу понять, почему это не так, когда вызывается в Base()
. Я получаю ошибку:
t1.cpp: In constructor ‘Base<Real>::Base(const TST&)’:
t1.cpp:20:15: error: expected primary-expression before ‘int’
t1.cpp:20:15: error: expected ‘;’ before ‘int’