Skip to content

Instantly share code, notes, and snippets.

@sheijk
Created December 23, 2011 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheijk/1512400 to your computer and use it in GitHub Desktop.
Save sheijk/1512400 to your computer and use it in GitHub Desktop.
Simple way of moving private non-virtual methods out of .h
// -----------------------------------------------------------------------------
// 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