samedi 1 août 2015

getting this type in object declaration context

As for the research I've done there is no good method to get the type of the enclosing class in static context. What about non-static context.

example:

template<typename TOwner, typename T>
struct prop {
    typedef TOwner Owner;

    prop(TOwner* owner) {
    }
};

struct MyType {
    prop<MyType, short> my_prop = {this};
    prop<decltype(my_prop)::Owner, long> prp = {this};
};

This code works, great. But try to replace MyType with decltype(*this) and it stops working saying this can not be declared in a static context. However my_prop can not be considered a static context as well and is more or less in the same context as this (can be rephrased as this-> my_prop).

So my question is following: am I missing something or there really is no way to get type of this even in non-static context while declaring property?

Aucun commentaire:

Enregistrer un commentaire