Created
January 12, 2012 01:58
-
-
Save hisui/1598057 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct SecretLove | |
{ | |
SecretLove(const std::string &msg) | |
:msg_4_u(msg) | |
{ | |
} | |
private: | |
void hoge() | |
{ | |
std::cerr << "(^_^;)" << std::endl; | |
} | |
std::string msg_4_u; | |
}; | |
// メンバ変数用 | |
template<typename T, typename MemType, MemType T::* Ptr> struct memvar | |
{ | |
struct accessor { static MemType T::* ptr; }; | |
}; | |
template<typename T, typename MemType, MemType T::* Ptr> | |
MemType T::* memvar<T,MemType,Ptr>::accessor::ptr = Ptr; | |
// メンバ関数用 | |
template<typename T, void (T::*Ptr)()> struct memfun | |
{ | |
struct accessor { static void (T::*ptr)(); }; | |
}; | |
template<typename T, void (T::*Ptr)()> | |
void (T::*memfun<T,Ptr>::accessor::ptr)() = Ptr; | |
int main() | |
{ | |
typedef typename memvar<SecretLove,std::string,&SecretLove::msg_4_u>::accessor acc_msg_4_u; | |
typedef typename memfun<SecretLove,&SecretLove::hoge>::accessor acc_hoge; | |
SecretLove love("(^3^) chu-!"); | |
std::cerr << "Message: " << love.*acc_msg_4_u::ptr << std::endl; | |
love.*acc_msg_4_u::ptr = "('A`) hate hate hate!"; | |
std::cerr << "Message: " << love.*acc_msg_4_u::ptr << std::endl; | |
(love.*acc_hoge::ptr)(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment