template<typename T, typename U>
class e
{
void Print() //call this function!
{
std::cout << "You haxxor..." << std::endl;
}
public:
T g()
{
return&U::Print;
}
};
You cannot modify this code in any way, nor can to create preprocessor definitions that will modify the class. The point is to call the Print function from this class, the output is unimportant. You may create one class, and the class cannot extend the above class. You cannot do something hacky like casting function pointers.
Tip: If you can get an instance of the class, you're on the right track.
EDIT: My compiler is too stupid to know this isn't possible.
I think I've seen this here before. The problem is that e<A, B> does not have access to the privates of e<A, C>, so U would have to be an infinite type, which I don't think can be done.
Maybe this is different across compilers. What are you using?
@Catfish: close, but you need the additional class I mentioned. Your code doesn't exactly compile on some compilers because e<int, int> has int g(){ return&int::Print; } (unless it is standard defined that unused functions need not be syntactically correct?)
Catfish it was exactly like yours but with Print being a function in the other class rather than a variable. I'll copypaste it when I get home to the computer that has it. The compiler is whichever one VC++2008 uses.