A
Amal P
Dears,
I have a question.
class Data
{
};
class DisableDerive:virtual protected Data // A base class
{
private:
DisableDerive(){}; // Made the constructor as private
friend class NonDerivable; // Made NonDerivable as friend so that
it can access private constructor
};
class NonDerivable: virtual protected DisableDerive // Intermediate
class - Virtual base
{
private:
int m_nVal;
public:
NonDerivable(){ m_nVal = -1;};
void SetValue( int nVal ){ m_nVal = 10; }
};
class TryDerive: public NonDerivable // Deriving from non derivable
class
{
};
int main()
{
TryDerive a;
return 0;
}
The above code does not allow to derive from class TryDerive. It gives
error on line TryDerive a. But when i changed the code as below it is
compiling.
class Data
{
};
class DisableDerive:virtual protected Data // A base class
{
private:
~DisableDerive(){}; // Made the constructor as private
friend class NonDerivable; // Made NonDerivable as friend so that
it can access private constructor
};
class NonDerivable: virtual protected DisableDerive // Intermediate
class - Virtual base
{
private:
int m_nVal;
public:
NonDerivable(){ m_nVal = -1;};
void SetValue( int nVal ){ m_nVal = 10; }
};
class TryDerive: public NonDerivable // Deriving from non derivable
class
{
};
int main()
{
TryDerive a;
return 0;
}
In the above code i changed the destructor as private.
What is the reason for this?
Thanks and regards,
Amal P.
I have a question.
class Data
{
};
class DisableDerive:virtual protected Data // A base class
{
private:
DisableDerive(){}; // Made the constructor as private
friend class NonDerivable; // Made NonDerivable as friend so that
it can access private constructor
};
class NonDerivable: virtual protected DisableDerive // Intermediate
class - Virtual base
{
private:
int m_nVal;
public:
NonDerivable(){ m_nVal = -1;};
void SetValue( int nVal ){ m_nVal = 10; }
};
class TryDerive: public NonDerivable // Deriving from non derivable
class
{
};
int main()
{
TryDerive a;
return 0;
}
The above code does not allow to derive from class TryDerive. It gives
error on line TryDerive a. But when i changed the code as below it is
compiling.
class Data
{
};
class DisableDerive:virtual protected Data // A base class
{
private:
~DisableDerive(){}; // Made the constructor as private
friend class NonDerivable; // Made NonDerivable as friend so that
it can access private constructor
};
class NonDerivable: virtual protected DisableDerive // Intermediate
class - Virtual base
{
private:
int m_nVal;
public:
NonDerivable(){ m_nVal = -1;};
void SetValue( int nVal ){ m_nVal = 10; }
};
class TryDerive: public NonDerivable // Deriving from non derivable
class
{
};
int main()
{
TryDerive a;
return 0;
}
In the above code i changed the destructor as private.
What is the reason for this?
Thanks and regards,
Amal P.