abstract base class
-
hello everyone, i have a simple inheritence question for anybody knows... let's take an example. I have the following class definition :
class CVCalcParserException {
protected:
int m_iExceptionNumber;
std::string m_strExceptionMsg;
int m_iErrorPos;public:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
virtual ~CVCalcParserException();
int GetExceptionNumber();
std::string GetMessage();
int GetErrorPos();
};In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as
CVCalcParserException
.is supposed to provide some services to the derived classes. How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0). any idea ?
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
hello everyone, i have a simple inheritence question for anybody knows... let's take an example. I have the following class definition :
class CVCalcParserException {
protected:
int m_iExceptionNumber;
std::string m_strExceptionMsg;
int m_iErrorPos;public:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
virtual ~CVCalcParserException();
int GetExceptionNumber();
std::string GetMessage();
int GetErrorPos();
};In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as
CVCalcParserException
.is supposed to provide some services to the derived classes. How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0). any idea ?
TOXCCT >>> GEII power
[toxcct][VisualCalc]Declare the constructor as protected.
class CVCalcParserException {
...
protected:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
hello everyone, i have a simple inheritence question for anybody knows... let's take an example. I have the following class definition :
class CVCalcParserException {
protected:
int m_iExceptionNumber;
std::string m_strExceptionMsg;
int m_iErrorPos;public:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);
virtual ~CVCalcParserException();
int GetExceptionNumber();
std::string GetMessage();
int GetErrorPos();
};In the current state of my class, people could be able to create an instance of it, but I'd like to forbbid this as
CVCalcParserException
.is supposed to provide some services to the derived classes. How could i set this class abstract ? the getter functions are not to be overloaded so i cannot put them as pure virtual functions (using =0). any idea ?
TOXCCT >>> GEII power
[toxcct][VisualCalc]How about making the constructor protected. If you do that it will be accessed only in derived class. Note: I never tried to do so. Why do you try and let me know too. Regards
-
Declare the constructor as protected.
class CVCalcParserException {
...
protected:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Declare the constructor as protected.
class CVCalcParserException {
...
protected:
CVCalcParserException(int iExceptionNumber,
const std::string& strExceptionMsg,
int iErrorPos);Regards Senthil _____________________________ My Blog | My Articles | WinMacro
tell me one more thing, i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters. should i also explicitely define this constructor protected ?
TOXCCT >>> GEII power
[toxcct][VisualCalc] -
tell me one more thing, i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters. should i also explicitely define this constructor protected ?
TOXCCT >>> GEII power
[toxcct][VisualCalc]toxcct wrote:
i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.
It doesn't. Explicitly defining a constructor suppresses generation of the compiler generated one, so no, you don't need to define the parameterless constructor. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
toxcct wrote:
i explicitely define only one constructor with parameters, so, the compiler implicitely defines a default constructor without parameters.
It doesn't. Explicitly defining a constructor suppresses generation of the compiler generated one, so no, you don't need to define the parameterless constructor. Regards Senthil _____________________________ My Blog | My Articles | WinMacro