Hi,
I write simple class to transform member function into non member
function
(with some rearrangement of its parameter).
The code is:
template<class T_, int (T_::*mfn_)()>
class Mfn {
public:
static int fn(T_* pT) { return (pT->*mfn_)(); }
};
and then try it with some test class like this:
class Test {
private:
// note that this member function is private
int test()
{
std::cout << "Test::test()" << std::endl;
return 0;
}
};
Then Mfn is used like this:
Test t;
Mfn<Test, &Test::test>::fn(&t);
The question is: "What is the sensible behavior of this code?"
Possible answer is:
1. Fail to compile outside of class "Test" (if it is used inside Test,
it should be OK)
2. Undefined behavior
I have tested it and the code compiles cleanly for 1 compiler (I don't
know about other compiler)
but if I change the member function to static and change the template
parameter accordingly,
it obviously failed as I expected.
I expected the test code to fail outside class "Test"
I don't really know if the standard defined this case or not.
Regards,
Ekaphol
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]