I want to do something like:
/*
* Superclass.h
*
*/
class Superclass
{
const int size;
public:
Superclass():size(1){}
~Superclass(){}
};
/*
* 开发者_StackOverflowSubclass.h
*
*/
#include "Superclass.h"
class Subclass : public Superclass
{
public:
Subclass(){size;}
~Subclass(){}
};
Use protected
instead of private
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) {}
精彩评论