Hi!
In my program, I've been wanting to determine the the derived type of a base class. So far, this seems to work fine:
Code:class BaseClass { public: template<class derived> void PrintType(derived object) { cout << "type: " << typeid(object).name() << endl; } }; class DerivedClass : public BaseClass { protected: void Foo() { PrintType(*this); } }; int main() { DerivedClass test_object; test_object.Foo(); cin.get(); }
However, in the context of what I intend to write, PrintType() is always called within a derived class of BaseClass and the argument is always going to be *this" (with or without * works for me). Not only will the argument always be the same, but it is the only argument for my program to function as I want it. So I was wondering: is there a way to re-write PrintType() such that it has it takes no arguments and can deduce the derived type on its own?
Thanks!