473,805 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>overrideconst ness.cpp

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

1c:\programming \constness\over rideconstness.c pp(3) : see declaration of
'ISkewEstimator ::get_Sum'

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

1>c:\programmin g\constness\ove rrideconstness. 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\over rideconstness.c pp(3) : see declaration of
'ISkewEstimator ::get_Sum'
Mar 20 '07 #1
9 1797

"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:Ow******** ******@TK2MSFTN GP04.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>overrideconst ness.cpp

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

1c:\programming \constness\over rideconstness.c pp(3) : see declaration of
'ISkewEstimator ::get_Sum'

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

1>c:\programmin g\constness\ove rrideconstness. 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\over rideconstness.c pp(3) : see declaration of
'ISkewEstimator ::get_Sum'


Mar 20 '07 #2

"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:uE******** ******@TK2MSFTN GP05.phx.gbl...
>
"Ben Voigt" <rb*@nospam.nos pamwrote in message
news:Ow******** ******@TK2MSFTN GP04.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

};

CSkewEstimat or skewInstance;



1>overridecons tness.cpp

1>c:\programmi ng\constness\ov errideconstness .cpp(8) : warning C4301:
'CSkewEstimato r::get_Sum': overriding virtual function only differs from
'ISkewEstimato r::get_Sum' by const/volatile qualifier

1c:\programmin g\constness\ove rrideconstness. cpp(3) : see declaration of
'ISkewEstimato r::get_Sum'

1>c:\programmi ng\constness\ov errideconstness .cpp(8) : error C3668:
'CSkewEstimato r::get_Sum' : method with override specifier 'override' did
not override any base class methods

1>c:\programmi ng\constness\ov errideconstness .cpp(11) : error C2259:
'CSkewEstimato r' : cannot instantiate abstract class

1due to following members:

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

1c:\programmin g\constness\ove rrideconstness. cpp(3) : see declaration of
'ISkewEstimato r::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.infoa ve.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******** ******@TK2MSFTN GP06.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
6404
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 unecessary? Here is an example of a Python class with all three types of methods (instance, static, and class methods). # Example from Ch.23, p.381-2 of Learning Python, 2nd ed. class Multi:
0
2273
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 3 colums, 1 and 3 with titles and the 2 with a big image. Well, 1 and 3 are not perfectly at the top of their column while 2 is even worst...with the image going down and down. Opera and Firefox even showing different errors with the background...
19
3303
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 IE so I drew conclusions only to discover that it worked even with <a name="xtop"></a> but not in Opera. IE6 understands "top" to mean *the top* !
6
7069
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 does not.
0
1433
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 that I can drop into the beginning of any page and it will generate HTML to display my logo, a link, and (optionally) a quote of the day, all of which will be horizontally centered at the top of the page by my default stylesheet. For the main page,...
5
5806
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 that I can drop into the beginning of any page and it will generate HTML to display my logo, a link, and (optionally) a quote of the day, all of which will be horizontally centered at the top of the page by my default stylesheet. For the main page,...
23
1726
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 written my own module, which works similarly but is somewhat extended. Here is an example of how it can be used and how I would like to use it but get stuck. from extreme import Top
2
7136
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 there is a large margin at the top. Thank you. My code is as follows: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Liken - A Series of Movies the Whole Family Can Enjoy</title> <style...
6
2034
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 possible to somehow know the top, left position of the content rendered by a User Control in a asp page. For eg, assume the figure below as a web page and A and B as user controls
2
2141
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 changes the pixel measurment into cm then the box is moved to a specific starting point when it is multiplied by 16.78.
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.