473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

top-level const-ness inhibits override

Found another variation on my previous bug
(https://connect.microsoft.com/Visual...dbackID=100917)
I would welcome validation and votes.


class ISkewEstimator

{

virtual void get_Sum(double* const pdRetval) const = 0;

};

class CSkewEstimator : public ISkewEstimator

{

virtual void get_Sum(double* pdRetval) const override; // remove explicit
override for other compilers

};

CSkewEstimator skewInstance;



1>overrideconstness.cpp

1>c:\programming\constness\overrideconstness.cpp(8 ) : warning C4301:
'CSkewEstimator::get_Sum': overriding virtual function only differs from
'ISkewEstimator::get_Sum' by const/volatile qualifier

1c:\programming\constness\overrideconstness.cpp(3) : see declaration of
'ISkewEstimator::get_Sum'

1>c:\programming\constness\overrideconstness.cpp(8 ) : error C3668:
'CSkewEstimator::get_Sum' : method with override specifier 'override' did
not override any base class methods

1>c:\programming\constness\overrideconstness.cpp(1 1) : error C2259:
'CSkewEstimator' : cannot instantiate abstract class

1due to following members:

1'void ISkewEstimator::get_Sum(double *const ) const' : is abstract

1c:\programming\constness\overrideconstness.cpp(3) : see declaration of
'ISkewEstimator::get_Sum'
Mar 20 '07 #1
9 1775

"Ben Voigt" <rb*@nospam.nospamwrote in message
news:Ow**************@TK2MSFTNGP04.phx.gbl...
Found another variation on my previous bug
(https://connect.microsoft.com/Visual...dbackID=100917)
I would welcome validation and votes.
I'd also appreciate it if someone with VC2003 could test (take off the
explicit override keyword) and see if it is a regression, I believe that it
worked ok there.
>

class ISkewEstimator

{

virtual void get_Sum(double* const pdRetval) const = 0;

};

class CSkewEstimator : public ISkewEstimator

{

virtual void get_Sum(double* pdRetval) const override; // remove explicit
override for other compilers

};

CSkewEstimator skewInstance;



1>overrideconstness.cpp

1>c:\programming\constness\overrideconstness.cpp(8 ) : warning C4301:
'CSkewEstimator::get_Sum': overriding virtual function only differs from
'ISkewEstimator::get_Sum' by const/volatile qualifier

1c:\programming\constness\overrideconstness.cpp(3) : see declaration of
'ISkewEstimator::get_Sum'

1>c:\programming\constness\overrideconstness.cpp(8 ) : error C3668:
'CSkewEstimator::get_Sum' : method with override specifier 'override' did
not override any base class methods

1>c:\programming\constness\overrideconstness.cpp(1 1) : error C2259:
'CSkewEstimator' : cannot instantiate abstract class

1due to following members:

1'void ISkewEstimator::get_Sum(double *const ) const' : is abstract

1c:\programming\constness\overrideconstness.cpp(3) : see declaration of
'ISkewEstimator::get_Sum'


Mar 20 '07 #2

"Ben Voigt" <rb*@nospam.nospamwrote in message
news:uE**************@TK2MSFTNGP05.phx.gbl...
>
"Ben Voigt" <rb*@nospam.nospamwrote in message
news:Ow**************@TK2MSFTNGP04.phx.gbl...
>Found another variation on my previous bug
(https://connect.microsoft.com/Visual...dbackID=100917)
I would welcome validation and votes.

I'd also appreciate it if someone with VC2003 could test (take off the
explicit override keyword) and see if it is a regression, I believe that
it worked ok there.
>>

class ISkewEstimator

{

virtual void get_Sum(double* const pdRetval) const = 0;

};

class CSkewEstimator : public ISkewEstimator

{

virtual void get_Sum(double* pdRetval) const override; // remove explicit
override for other compilers

};

CSkewEstimator skewInstance;



1>overrideconstness.cpp

1>c:\programming\constness\overrideconstness.cpp( 8) : warning C4301:
'CSkewEstimator::get_Sum': overriding virtual function only differs from
'ISkewEstimator::get_Sum' by const/volatile qualifier

1c:\programming\constness\overrideconstness.cpp(3 ) : see declaration of
'ISkewEstimator::get_Sum'

1>c:\programming\constness\overrideconstness.cpp( 8) : error C3668:
'CSkewEstimator::get_Sum' : method with override specifier 'override' did
not override any base class methods

1>c:\programming\constness\overrideconstness.cpp( 11) : error C2259:
'CSkewEstimator' : cannot instantiate abstract class

1due to following members:

1'void ISkewEstimator::get_Sum(double *const ) const' : is abstract

1c:\programming\constness\overrideconstness.cpp(3 ) : see declaration of
'ISkewEstimator::get_Sum'


I used VS2003 to compile it.

test.cpp(10) : warning C4301: 'CSkewEstimator::get_Sum': overriding virtual
function only differs from 'ISkewEstimator::get_Sum' by const/volatile
qualifier

test.cpp(5) : see declaration of 'ISkewEstimator::get_Sum'

test.cpp(14) : error C2259: 'CSkewEstimator' : cannot instantiate abstract
class

due to following members:

'void ISkewEstimator::get_Sum(double *const ) const' : pure virtual function
was not defined

test.cpp(5) : see declaration of 'ISkewEstimator::get
Mar 20 '07 #3
int main()

{

class ISkewEstimator

{

virtual void get_Sum(double* const pdRetval)const = 0;

};

class CSkewEstimator : public ISkewEstimator

{

virtual void get_Sum(double* const pdRetval)const override{};

};

CSkewEstimator skewInstance;

return 0;

};

This compiles with VC2005.


Mar 22 '07 #4

"eddie geer" <gg***@blomand.netwrote in message
news:et**********@news04.infoave.net...
int main()

{

class ISkewEstimator

{

virtual void get_Sum(double* const pdRetval)const = 0;

};

class CSkewEstimator : public ISkewEstimator

{

virtual void get_Sum(double* const pdRetval)const override{};

};

CSkewEstimator skewInstance;

return 0;

};

This compiles with VC2005.
You added const, where it is not necessary according to the C++ standard.
What if the implementation CSkewEstimator::get_Sum actually did modify its
local copy of the pointer? You would have to change the interface
declaration because of an implementation detail. What if some
implementations of get_Sum treat the argument as const and some do not (not
referring to the pointed-to location, which is non-const, but the pointer
itself)? Then you would have to sacrifice const-correctness in order to
compile.

I shouldn't have to modify standards-compliant code that is developed with
gcc, to have VC++ compile it. I presented a minimal example, there are many
more member functions and several classes are affected.
Mar 22 '07 #5
Ben Voigt wrote:
You added const, where it is not necessary according to the C++ standard.
I agree, you should be able to create a const interface for that
non-const argument.

I have validated your bug, I'm getting the same errors on my VS2003 and
VS2005 SP1.

http://www.comeaucomputing.com/tryitout/ liked your code and compiled it
without errors. Interestingly, your code works on Borland C++Builder 6,
which gets quite a lot of complaints for its non-standards compliance.

On http://dinkumware.com/exam/, only MINGW compiled it successfully.

Tom
Mar 22 '07 #6
Here's a workaround, but it's very painful if it affects a lot of
functions, and it's a performance hit as well, since you need to call
yet another virtual function:

class CSkewEstimator : public ISkewEstimator
{

virtual void get_Sum(double* const pdRetval) const override
{ get_SumNonCost(pdRetval); }
virtual void get_SumNonCost(double* pdRetval) const { }

};
Mar 22 '07 #7

"Tamas Demjen" <td*****@yahoo.comwrote in message
news:eh**************@TK2MSFTNGP06.phx.gbl...
Here's a workaround, but it's very painful if it affects a lot of
functions, and it's a performance hit as well, since you need to call yet
another virtual function:
Actually, the shim needs to be virtual, but the implementation doesn't.

I had less than two dozen functions total, and my interfaces were for
decoupling rather than polymorphism, so I had already made the interface
match exactly, but I wanted to get the bug validated because rejecting
compliant code obviously isn't pretty.
>
class CSkewEstimator : public ISkewEstimator
{

virtual void get_Sum(double* const pdRetval) const override
{ get_SumNonCost(pdRetval); }
virtual void get_SumNonCost(double* pdRetval) const { }

};

Mar 22 '07 #8
Ben Voigt wrote:
I wanted to get the bug validated because rejecting
compliant code obviously isn't pretty.
If you need more confirmation, I have the standard draft in front of me,
date: 2005-10-19, page 247, 13.1 Overloading:

"Parameter declarations that differ only in the presence or absence of
const and/or volatile are equivalent. That is, the const and volatile
type-specifiers for each parameter type are ignored when determining
which function is being declared, defined, or called."

"Only the const and volatile type-specifiers at the outermost level of
the parameter type specification are ignored in this fashion"

So "double* pdRetval" is equivalent to "double* const pdRetval" from the
overload's point of view.

Obviously "double*" is not equivalent to "const double*".
Mar 22 '07 #9
Tamas Demjen wrote:
Ben Voigt wrote:
>You added const, where it is not necessary according to the C++ standard.

I agree, you should be able to create a const interface for that
non-const argument.

I have validated your bug, I'm getting the same errors on my VS2003 and
VS2005 SP1.

http://www.comeaucomputing.com/tryitout/ liked your code and compiled it
without errors. Interestingly, your code works on Borland C++Builder 6,
which gets quite a lot of complaints for its non-standards compliance.

On http://dinkumware.com/exam/, only MINGW compiled it successfully.

Tom
Interesting - I wonder if the Dinkumware exam site uses any of the
compatibility switches for the EDG front end (or perhaps uses the
default switches on Windows, which will enable MS compatibility mode),
since I'd be quite surprised if EDG had this bug in their ISO compliant
mode. Also, Comeau C++ compiles it fine.

Tom
Mar 23 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

145
by: David MacQuigg | last post by:
Playing with Prothon today, I am fascinated by the idea of eliminating classes in Python. I'm trying to figure out what fundamental benefit there is to having classes. Is all this complexity...
0
by: Ataru Morooka | last post by:
Hello, I am renewing a website using CSS and I have some problems with IE6. Following this link: http://www.ansv.it/templates/Template_Index_IT.dwt.asp you may notice that the container area has...
19
by: Mason A. Clark | last post by:
How was I to know that "top" means "top" in MSIE6 ?? I was testing <a name="top"></a> at the top of the page with <a href="#top>go to top</a> at the bottom of the page. It always worked in...
6
by: Mason A. Clark | last post by:
LAST WORD(s): 1. MSIE6 and Firefox will go to the top of the page on command <a href="#top">go upsy</a> even if there is NO name="top" or id="top" They know what a "top" is :-) Opera...
0
by: BACON | last post by:
I'm just starting the process of reorganising my modest little website and cleaning up all the HTML, and the logical place to begin was with the homepage. I made a simple little ASP.NET control...
5
by: BACON | last post by:
I'm just starting the process of reorganising my modest little website and cleaning up all the HTML, and the logical place to begin was with the homepage. I made a simple little ASP.NET control...
23
by: Antoon Pardon | last post by:
I know this PEP is rejected. However I have a problem that would benefit from having extreme values and the sample implementation that is given in the PEP is unsatifactory for my purpose. I had...
2
by: levilarsen | last post by:
Hi, thanks for reading this post. I have a web page that displays fine in IE but in Firefox and Safari there is a space at the top of the web page. It is as if the whole page is pushed down, like...
6
by: Samuel Rhodes | last post by:
Hi I am trying to write a code snippet that would display a '?' sign on the top left of a control. I do not want to hard code the positioning of the DIV which will contain that '?'. Is it...
2
by: noe1818 via AccessMonster.com | last post by:
Can anyone tell my why this isn't working? Me!.top=(1440/2.54)*16.78-*0.4) I want it so that for every 1 change in , a rectangular box moves 0.4 units closer to the top. The 1440/2.54...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.