tags:

views:

61

answers:

2

I want to do something like:

/*
 * Superclass.h
 *
 */

class Superclass
{
const int size;

public:
    Superclass():size(1){}
    ~Superclass(){}
};


/*
 * Subclass.h
 *
 */

#include "Superclass.h"

class Subclass : public Superclass
{

public:
    Subclass(){size;}
    ~Subclass(){}
};
+5  A: 

Use protected instead of private

bshields
Or add a protected method to SuperClass that returns a reference to the private member.
Martin York
+2  A: 

It seems that you need to access it only for construction. In that case, make a constructor which accepts the value:

Superclass(int size_value=1) : size(size_value) {}

Then use it in the subclass constructor, e.g.:

Subclass() : Superclass(5) {}
zvonimir