A
Amal
Hey,
I felt it hard to see such an issue in Microsoft Visual C++ 2008
kept unfixed. I reported an issue that the private virtual base
destructor is being accessed by most derived class for Microsoft
Visual C++ 2005 & 2003. And this issue still persist on Microsoft
Visual C++ 2008. It is hard to see this being a developer who uses
Microsoft Compiler.
The problem is detailed at blog entry
http://amalp.blogspot.com/2007/07/microsoft-vc-2005-compiler-bug-1.html
I will also explain the problem out here.
In C++ there is no standard way to make a class non derivable.
Instead we uses a trick. The trick consist of 2 major concepts. One is
the virtual base class constructor and destructor will be called by
the most derived class. Most derived class is the class which is
instantiated. This is how we fix the diamond problem. Then the second
one is a friend class can access private members of whom it is friend.
Mixing up both of these together we can make a class non derivable.
The same access goes to constructor and destructor.
class DisableDerive
{
public:
DisableDerive(){ ; }
private:
~DisableDerive(){ ; }
friend class NonDerivable;
};
class NonDerivable: virtual protected DisableDerive
{
private:
int m_nVal;
public:
NonDerivable()
{
std::cout<<"NonDerivable::NonDerivable()\n";
m_nVal = -1;
}
~NonDerivable()
{
std::cout<<"NonDerivable::~NonDerivable()\n";
}
void SetValue( int nVal ){ m_nVal = 10; }
};
class TryDerive: public NonDerivable
{
public:
TryDerive(){ ; }
~TryDerive(){ ; }
};
int main()
{
TryDerive a;
return 0;
}
See the above program. In the above program the destructor of the
DisableDerive class has to be called by the class TryDerive since the
class NonDerivable is derived from DisableDerive virtualy. Since the
destructor of DisableDerive is private the TryDerive must not be
capable of calling it. But IT IS GETTING CALLED in all VC++ compilers
after Microsoft Visual C++ 6.0. VC 6.0 have correct behavior on it.
And the most interesting thing is if the constructor of the class
DisableDerive is made private the compiler gives an expected error
error C2248: 'DisableDerive:isableDerive' : cannot access private
member declared in class 'DisableDerive'.
I don't understand why Microsoft feel this bug need not be fixed.
Is it a real hard issue to fix? After Visual C++ 6.0 each version have
this bug. And this bug reported when Orcas was at beta1 stage. Also
Microsoft accepted it is an issue. But they didn't fix.
Thanks and Regards,
Amal P
I felt it hard to see such an issue in Microsoft Visual C++ 2008
kept unfixed. I reported an issue that the private virtual base
destructor is being accessed by most derived class for Microsoft
Visual C++ 2005 & 2003. And this issue still persist on Microsoft
Visual C++ 2008. It is hard to see this being a developer who uses
Microsoft Compiler.
The problem is detailed at blog entry
http://amalp.blogspot.com/2007/07/microsoft-vc-2005-compiler-bug-1.html
I will also explain the problem out here.
In C++ there is no standard way to make a class non derivable.
Instead we uses a trick. The trick consist of 2 major concepts. One is
the virtual base class constructor and destructor will be called by
the most derived class. Most derived class is the class which is
instantiated. This is how we fix the diamond problem. Then the second
one is a friend class can access private members of whom it is friend.
Mixing up both of these together we can make a class non derivable.
The same access goes to constructor and destructor.
class DisableDerive
{
public:
DisableDerive(){ ; }
private:
~DisableDerive(){ ; }
friend class NonDerivable;
};
class NonDerivable: virtual protected DisableDerive
{
private:
int m_nVal;
public:
NonDerivable()
{
std::cout<<"NonDerivable::NonDerivable()\n";
m_nVal = -1;
}
~NonDerivable()
{
std::cout<<"NonDerivable::~NonDerivable()\n";
}
void SetValue( int nVal ){ m_nVal = 10; }
};
class TryDerive: public NonDerivable
{
public:
TryDerive(){ ; }
~TryDerive(){ ; }
};
int main()
{
TryDerive a;
return 0;
}
See the above program. In the above program the destructor of the
DisableDerive class has to be called by the class TryDerive since the
class NonDerivable is derived from DisableDerive virtualy. Since the
destructor of DisableDerive is private the TryDerive must not be
capable of calling it. But IT IS GETTING CALLED in all VC++ compilers
after Microsoft Visual C++ 6.0. VC 6.0 have correct behavior on it.
And the most interesting thing is if the constructor of the class
DisableDerive is made private the compiler gives an expected error
error C2248: 'DisableDerive:isableDerive' : cannot access private
member declared in class 'DisableDerive'.
I don't understand why Microsoft feel this bug need not be fixed.
Is it a real hard issue to fix? After Visual C++ 6.0 each version have
this bug. And this bug reported when Orcas was at beta1 stage. Also
Microsoft accepted it is an issue. But they didn't fix.
Thanks and Regards,
Amal P