Q:

Call a C++ base class method automatically

I'm trying to implement the command design pattern, but I'm stumbling accross a conceptual problem.  Let's say you have a base class and a few subclasses like in the example below:
class Command : public boost::noncopyable {
    virtual ResultType operator()()=0;

    //Restores the model state as it was before command's execution. 
    virtual void undo()=0;

    //Registers this command on the command stack. 
    void register();
};

class SomeCommand : public Command {
    virtual ResultType operator()(); // Implementation doesn't really matter here
    virtual void undo(); // Same
};

The thing is, everytime operator () is called on a SomeCommand instance, I'd like to add *this to a stack (mostly for undo purposes) by calling the Command's register method.  I'd like to avoid calling "register" from SomeCommand::operator()(), but to have it called automaticaly (someway ;-) )
I know that when you construct a sub class such as SomeCommand, the base class constructor is called automaticaly, so I could add a call to "register" there.  The thing I don't want to call register until operator()() is called. 
How can I do this?  I guess my design is somewhat flawed, but I don't really know how to make this work. 

A:

It looks as if you can benefit from the NVI (Non-Virtual Interface) idiom.  There the interface of the command object would have no virtual methods, but would call into private extension points:
class command {
public:
   void operator()() {
      do_command();
      add_to_undo_stack(this);
   }
   void undo();
private:
   virtual void do_command();
   virtual void do_undo();
};

There are different advantages to this approach, first of which is that you can add common functionality in the base class.  Other advantages are that the interface of your class and the interface of the extension points is not bound to each other, so you could offer different signatures in your public interface and the virtual extension interface.  Search for NVI and you will get much more and better explanations. 
Addendum: The original article by Herb Sutter where he introduces the concept (yet unnamed)

A:

Split the operator in two different methods, e.g. execute and executeImpl (to be honest, I don't really like the () operator).   Make Command::execute non-virtual, and Command::executeImpl pure virtual, then let Command::execute perform the registration, then call it executeImpl, like this:
class Command
   {
   public:
      ResultType execute()
         {
         ... // do registration
         return executeImpl();
         }
   protected:
      virtual ResultType executeImpl() = 0;
   };

class SomeCommand
   {
   protected:
      virtual ResultType executeImpl();
   };

