+1  A: 

Use a pure virtual class as an Interface and a good IDE with refactoring support.

Pure virtual classes are like an API contract (in other languages sometimes called Interface). You declare a method once and then inherit from it in the 3-4 other classes. You only change a method in the Interface and it gets changed in the dependent classes...or at least those won't compile any more and you know that you have to make the change there as well.

Read more about this e.g. in wikipedia.

Gerd Klima
Well, first of all it is for C++ so not sure if these tools support it... Secondly, the problem isn't the physical labour of duplicating - it is the maintenance of 4-5 400line method declarations.
lk
yep, but both the specific and the mock implementations need to implement all/most of the methods, so their header will still have to contain all the declarations
lk
@lk: removed the ReSharper reference as it does indeed not support C++. Sorry. I made my answer a little clearer...I hope.
Gerd Klima
@lk: Maybe I still get something wrong...or I forgot too much about C++ in the last few years...have to check but I didn't think you would need the declarations in both header files, only in one. BTW: I'm adding a new answer for a different way
Gerd Klima
A: 

One way to do it is using refactoring tools; most modern IDEs have that. For example, the Eclipse CDT has a refactor option. Gerd also suggested one.

Another way is to use a code instrumentation tool like pin. These tools are used mainly for profiling, but might suit your purpose.

UPDATE:

If your problem isn't much about writing code, but more at maintainence, I think pin is a decent option (run-time change). Another way is to use aspect oriented programming. For example, Aspect C++.

rxin
Again, the problem isn't the work of writing the code - sed/perl do amazing jobs at this! :-)
lk
k... updated..............
rxin
A: 

Write a little code generator that takes the method declarations from the main header file and copies them to the SpecificImpl and MockImpl header files.

Gerd Klima
+3  A: 

What about something like this:

//=======================================
// Macro definition of method list
//=======================================
#define METHOD_LIST(ABSTRACT) \
    virtual void Foo1() ABSTRACT; \
    virtual void Foo2() ABSTRACT; \
    virtual void Foo3() ABSTRACT

//=======================================
// Declaration of Abstract base class
//=======================================
class IBase
{
public:
    METHOD_LIST( = 0);
};

//=======================================
// Declaration of Specific
//=======================================
class CSpecific : public IBase
{
public:
    METHOD_LIST();
};

//=======================================
// Declaration of Mock class
//=======================================
class CMock : public IBase
{
public:
    METHOD_LIST();
};

Update...

If you want to make it even more macro-cryptic, you may change the macro to:

#define METHOD_LIST(VIRTUAL, ABSTRACT) \
    VIRTUAL void Foo1() ABSTRACT; \
    VIRTUAL void Foo2() ABSTRACT;

and this will allow you to declare the regular function list that is not part of any object too:

For abstract class:

METHOD_LIST(virtual, =0)

For derived class:

METHOD_LIST(virtual, ;)

For regular function list:

METHOD_LIST(;, ;)

If you need to debug this mess, then I recommend using 'g++ -M' to see the result of the preprocessor .

A: 

If this is a common problem, then learn to use templates, and look into generic/generative/meta- programming techniques. (teh rabbit-hole is deep)

Justin