How to add a member to a ...

Why would you ever want to add a member to a source file and not to a header file?

One reason might be to implement an Opaque Data Type or an Opaque Pointer.

If you want to end up with this code:

// main.cpp

#include "foo.h"

int main()
{
    foo a_foo;
    a_foo.bar();

    return 0;
} // function body

==================

// foo.h

#ifndef FOO_IS_INCLUDED
#define FOO_IS_INCLUDED

/* concrete */ class foo_impl;

/* concrete */ class foo
{
public:
    foo();

    ~foo();

    void bar();

private:
    foo_impl * my_impl;
}; // class foo

#endif // FOO_IS_INCLUDED

==================

// foo.cpp

#include "foo.h"

/* concrete */ class foo_impl
{
public:
    void bar();
}; // class foo_impl

void foo_impl::bar()
{
} // function body

foo::foo()
: my_impl{new foo_impl{}}
{
} // function body

foo::~foo()
{
    delete my_impl;
} // function body

void foo::bar()
{
    my_impl->bar();
} // function body
then you would: