A
andreykuzmenko
I'm thinking about using templates instead of virtual methods to boost
the performance of my library. I would like to know if it is possible
to do something like the following:
template<class T>
void just_do_it(T* t)
{
t->do_it();
}
Of course we do not know whether class T has do_it() method or not. But
will this work out? For the following example it would be cool if it
would generate compile error if MyClass doesn't have do_it() method,
and compile correctly if it has:
MyClass myc = new MyClass();
just_do_it<MyClass>(my);
So, is it possible? If not, then why? I think it would be very nice
the performance of my library. I would like to know if it is possible
to do something like the following:
template<class T>
void just_do_it(T* t)
{
t->do_it();
}
Of course we do not know whether class T has do_it() method or not. But
will this work out? For the following example it would be cool if it
would generate compile error if MyClass doesn't have do_it() method,
and compile correctly if it has:
MyClass myc = new MyClass();
just_do_it<MyClass>(my);
So, is it possible? If not, then why? I think it would be very nice