I
Ivan Vecerina
Here's a relatively simple code snippet:
#include <memory>
class Base {
public:
Base();
virtual ~Base();
virtual void f(int a, char const* name);
};
class Sub : public Base {
public:
Sub();
virtual ~Sub();
// **PROBLEM 1** : incorrect warning
virtual void f(int a, char const* const name);
};
class Other { //NB: forgot to specify base class
public:
Other();
virtual ~Other();
virtual void f(int a, char const* const name);
};
std::auto_ptr<Base> factory()
{
// **PROBLEM 2** : this should be a compilation error
return std::auto_ptr<Base>( new Other() );
}
**PROBLEM 1** : VS2005 reports the following warning:
Warning 2 warning C4301: 'Sub::f': overriding virtual function only
differs from 'Base::f' by const/volatile qualifier
c:\dev\ivec_dev\ivec\render\image\imagelogger.cpp 23
But the added "top-level" const is not part of the function's signature,
so the code is perfectly legit.
**PROBLEM 2** : VS2005 generates invalid code
This should trigger a compilation error, because Other is
not a subclass of Base. Somehow this slips through,
and invalid code is generated (the pointer value somehow
gets garbled...). (compiler or library bug??)
Any luck to see those fixed in the upcoming service pack?
#include <memory>
class Base {
public:
Base();
virtual ~Base();
virtual void f(int a, char const* name);
};
class Sub : public Base {
public:
Sub();
virtual ~Sub();
// **PROBLEM 1** : incorrect warning
virtual void f(int a, char const* const name);
};
class Other { //NB: forgot to specify base class
public:
Other();
virtual ~Other();
virtual void f(int a, char const* const name);
};
std::auto_ptr<Base> factory()
{
// **PROBLEM 2** : this should be a compilation error
return std::auto_ptr<Base>( new Other() );
}
**PROBLEM 1** : VS2005 reports the following warning:
Warning 2 warning C4301: 'Sub::f': overriding virtual function only
differs from 'Base::f' by const/volatile qualifier
c:\dev\ivec_dev\ivec\render\image\imagelogger.cpp 23
But the added "top-level" const is not part of the function's signature,
so the code is perfectly legit.
**PROBLEM 2** : VS2005 generates invalid code
This should trigger a compilation error, because Other is
not a subclass of Base. Somehow this slips through,
and invalid code is generated (the pointer value somehow
gets garbled...). (compiler or library bug??)
Any luck to see those fixed in the upcoming service pack?