Searching the site I found this answer for getting a type of a member inside a class. Based on that I made the following example which compiles succesfully.
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
class sig_class_t{
public:
int field;
};
class usig_class_t{
public:
unsigned int field;
};
template <class T, class M> M get_member_type(M T:: *);
template<typename my_class = sig_class_t, typename my_type = decltype(get_member_type(&my_class::field))>
class Tricky{
my_type it;
public:
my_type get_it();
void set_it(my_type value);
};
template<typename my_class, typename my_type>
my_type Tricky<my_class,my_type>::get_it(){
return it;
}
template<typename my_class, typename my_type>
void Tricky<my_class,my_type>::set_it(my_type value){
it = value;
}
int main(int argc, char *argv[])
{
return 0;
}
How does get_member_type
is able to decide the type of the given pointer?
This code seems a quite complex, and I would not be comfortable using it if I don't understand how it works.