Q:

How to create a derived class with same default constructor but with different value?

I have a class like this:
//class1.h

class Foo
{
private:
  int m_Value;
public:
  int Foo();
}

//class1.cpp

#include "class1.h"
#define CONST_VARIABLE 12

Foo::Foo()
{
  m_Value = CONST_VARIABLE;
}

and a derived class:
//class2.h

#include "class1.h"

class Foo2 : public Foo
{
puplic:
  Foo2();
  //other functions here
}

//class2.cpp

#define CONST_VARIABLE 24;
#include "class2.h"

Foo2::Foo2() : Foo()
{
}

However, when I called
Foo a;
Foo2 b;

Those 2 (a and b) have the same m_Value (which is 12).
I knew Foo2() will call Foo() first so m_Value will take the CONST_VARIABLE in class Foo. Thus, I try re-define it but with no luck.
Since both classes are initialized the same way but with different default values and I can't add parameter to the default constructor.
How can I create a derived class with same default constructor but with different value? And in the long run, I could easily maintain or modify the code by changing the the value quickly.

A:

You could use a protected constructor so that only derived classes can use the constructor specifying a different member value:
class Foo {
public:
    Foo();
protected:
    explicit Foo(int value);
private:
    int m_Value;
};

Foo::Foo() :
    m_Value(12)
{}

Foo::Foo(int value) :
    m_Value(value)
{}

class Foo2 {
public:
    Foo2();
};

Foo2::Foo2 :
    Foo(24)
{}

