Image

Imageex_beshenov wrote in Imagecpp 😤working

Listens: Public Image Limited -- Religion

C++ templates (beginner's question)

Hi!



How should I use pointers to functions defined with using of templates?

G++ says `address of overloaded function with no contextual type information` (see below).



~/fatherson.cpp:
#include <iostream>

template<typename T> class father {
  public:
     T (*pointer) (class father &arg);
     T z;
     father () { T (*pointer> (class father &arg) = NULL; }
};

template<typename T> T foo (class father<T> &arg) { return arg.z; }

long double foo (class father<long double> &arg);

template<typename T> class son: private father<T> {
  public:
     T method () {
        if (pointer!=&foo) { return foo(*this); }
        else { exit(0); }
     }
};

int main () {
  son<long double> a;
  std::cout << a.method() << std::endl;
  return 0;
}





# g++ ~/fatherson.cpp -o ~/fatherson
~/fatherson.cpp: In member function `T son<T>::method() [with T = long double]':
~/fatherson.cpp:24:   instantiated from here
~/fatherson.cpp:17: error: address of overloaded function with no contextual
  type information