Can anyone explain why this code fails to compile?
#include <iostream>
void func()
{
std::cout << "success!\n ";
}
struct S
{
template <class F>
void method(const F& f)
{
f();
}
};
int main()
{
S s;
s.method(func);
}
but with a very slight change to main
int main()
{
S s;
s.method(&func) ; // change here
}
it compiles and works.
john
#include <iostream>
void func()
{
std::cout << "success!\n ";
}
struct S
{
template <class F>
void method(const F& f)
{
f();
}
};
int main()
{
S s;
s.method(func);
}
but with a very slight change to main
int main()
{
S s;
s.method(&func) ; // change here
}
it compiles and works.
john
Comment