Created
September 11, 2009 19:01
-
-
Save frsyuki/185506 to your computer and use it in GitHub Desktop.
This file contains 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> | |
// header | |
class Test { | |
public: | |
void func(); | |
private: | |
class util; | |
friend class util; | |
int member1; | |
int member2; | |
}; | |
// source | |
class Test::util : public Test { | |
public: | |
int benri_func() const; | |
}; | |
int Test::util::benri_func() const | |
{ | |
return member1 + member2; | |
} | |
void Test::func() | |
{ | |
member1 = 1; | |
member2 = 2; | |
int val = static_cast<util*>(this)->benri_func(); | |
std::cout << val << std::endl; // 3 | |
} | |
int main(void) | |
{ | |
Test t; | |
t.func(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment