lundi 30 novembre 2015

Get class name of the caller that calls member function

I have a base class. One of its member function needs the name of the caller's class as one of the template argument. Let's call it "work".

template<typename T>
void work() {
    // ...
}

Then I may use it in this way, assuming that "obj1" and "obj2" are instances that subclasses the base class I just mentioned,

obj1.work<std::remove_reference<decltype(obj1)::type>>();
obj2.work<std::remove_reference<decltype(obj2)::type>>();

The trouble is that each time I need to use std::remove_reference and then decltype, despite that these types can be known before compiling. Can I somehow avoid writing them? Is there some macro that can help "generate" them? Thanks!

Aucun commentaire:

Enregistrer un commentaire