Created
December 23, 2011 00:03
-
-
Save sheijk/1512400 to your computer and use it in GitHub Desktop.
Simple way of moving private non-virtual methods out of .h
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
// ----------------------------------------------------------------------------- | |
// in foo.h | |
#ifndef FOO_H_2011_12_23_INCLUDED | |
#define FOO_H_2011_12_23_INCLUDED | |
class Foo | |
{ | |
friend class FooImpl; | |
int m_secret; | |
public: | |
Foo(); | |
}; | |
#endif | |
// ----------------------------------------------------------------------------- | |
// foo.cpp | |
#include "private_impl.h" | |
class FooImpl | |
{ | |
public: | |
static void helper(Foo* self) | |
{ | |
++self->m_secret; | |
} | |
}; | |
Foo::Foo() | |
{ | |
m_secret = 0; | |
FooImpl::helper(this); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment