c++c++11pointersstatictype-traits

Accessing static properties of a pointer type


I am trying to call a static method of a type in a tuple, but the tuple uses pointers, not the type itself. This means that when I use tuple_element I am getting a pointer type which I can not use to call the static method.

Does anyone know how to either convert a pointer type to its non-pointer equivalent, or access a static property of a pointer type?

struct Example
{
    static int example()
    {
        return 0;
    }
};

typedef Example* PointerType;

int main()
{
    PointerType::example(); // Nope
    (*PointerType)::example(); // Nope
    (typename *PointerType)::example(); // Nope
    (PointerType*)::example(); // Nope
}

Solution

  • You could use std::remove_pointer (since C++11) to get the type pointed to, e.g. (note std::remove_pointer_t is supported from C++14)

    std::remove_pointer_t<PointerType>::example();