See the example: compilable here
// Example program
#include <iostream>
#include <string>
class Foo {
public:
class Nes{};
void Nes(){}
using Ptr = void(Nes::*)();
};
template<typename T> class Bar
{
public:
using Ptr = void(T::Nes::*)();
};
int main()
{
using F = void(Foo::Nes::*)();
F compiles;
Bar<Foo>::Ptr notCompiles;
std::cout << typeid(Foo).name();
}
How can tell to the compiler that Nes should be the class and not the method?
In this case:
template<typename T> class Bar {
public:
using Ptr = typename T::Ptr;
};
If T doesn't have a Ptr type definition:
template <typename T> class Bar {
public:
using TNes = class T::Nes;
using Ptr = void (TNes::*)();
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With