我遇到了以下问题,我没有一个好主意。也许有人可以帮助我?
class Foo
{
// [Your code goes here]
// Rec1: Don’t write function call operator()
// Rec2: Don’t use macros.
};
int main()
{
Foo foo;
foo(); // This line prints “Hello World!”
}
#include <iostream>
class Foo
{
public:
using fncPntr = void(*)(void);
//Implicit conversion to a function pointer
operator fncPntr()
{
return &Print;
}
void static Print()
{
std::cout << "Hello World!";
}
};
int main()
{
Foo foo;
foo();
}
class Foo{
// [Your code goes here]
};
void foo()
{
std::cout << "hello";
}
class Bar{
// Rec1: Don’t write function call operator()
// Rec2: Don’t use macros.
};