Suppose that we have the following base and derived classes:
#include <string>
#include <iostream>
class Car {
public:
void Drive() { std::cout << "Baby, can I drive your car?" << std::endl; }
};
class Porsche : public Car {
};
..and also the following template function:
template <typename T, typename V>
void Function(void (T::*m1)(void), void (V::*m2)(void)) {
std::cout << (m1 == m2) << std::endl;
}
Why does this compile using GCC:
int main(int argc, char** argv) {
void (Porsche::*ptr)(void) = &Porsche::Drive;
Function(ptr, ptr);
return 0;
}
...but not this?
int main(int argc, char** argv) {
void (Porsche::*ptr)(void) = &Porsche::Drive;
Function(&Porsche::Drive, ptr);
return 0;
}