0

For example, install<double>(&T::print); could not pass compile. How could I pass T::print as parameter? Remove template <typename M> could pass compile. But I could not remove template <typename M>, because I need it in the true code. Thank you in advance.

#include <iostream>

template<typename T>
class Base
{
public:
  template <typename M>
  void install(void (T::*method)(int))
  {
    std::cout << "Hello" << std::endl;
  }
};

template<typename T>
class Child : public Base<T>
{
public:
  void test()
  {
    install<double>(
        &T::print);
  }
};

class Grandson : public Child<Grandson>
{
public:
  void print(int n)
  {
    std::cout << "Num:" << n << std::endl;
  }
};
haosdent
  • 815
  • 2
  • 7
  • 16
  • Related to [where-and-why-do-i-have-to-put-the-template-and-typename-keywords](/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – Jarod42 Aug 03 '15 at 02:40

1 Answers1

2

You have to call

this->template install<double>(&T::print);

Live Demo

Jarod42
  • 173,454
  • 13
  • 146
  • 250