What I want to do is have Init in a base template class and have it return its derived class. The code below doesn't work, but it illustrates what I wish to achieve.
Is there a way to accomplish this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
template <class T>
class A{
T *Init(){ returnthis; }
};
class B : public A<B>
{
public:
void Check(){}
};
int main(){
B Test;
Test.Init()->Check();
return 0;
}
template<class T>
class A {
public:
T *Init() {
returnstatic_cast<T*>(this);
}
};
class B: public A<B> {
public:
void Check() {}
};
int main() {
B Test;
Test.Init()->Check();
return 0;
}