473,324 Members | 2,417 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,324 software developers and data experts.

Overdone declarations ?

Hi,

suppose a collection type of class that might return references to
classes of type Object - it has (among others) access methods as follows:

virtual Object*& at(int) = 0;
virtual const Object *const& at(long) const = 0;

where the int and the long denote the internal order within the
collection, numbered from 0..[size-1]

My question is: what on earth does the second method return ? How come
anyone ever declares a method in that way ... would it be that bad to
rephrase it into the form of the first method ?

Thanks in advance :-)

Jul 19 '05 #1
1 1252
Mart Käsper <ma**@netsoftlund.se> writes:
Hi,

suppose a collection type of class that might return references to
classes of type Object - it has (among others) access methods as
follows:

virtual Object*& at(int) = 0;
virtual const Object *const& at(long) const = 0;

where the int and the long denote the internal order within the
collection, numbered from 0..[size-1]

My question is: what on earth does the second method return ?
It returns a reference which cannot be used to modify the pointer it
refers to, which pointer in turn cannot be used to modify the
Object it points to.

A decl of this sort must be read right-to-left:

const Object *const&

reads as: reference to const pointer to const Object.
How come
anyone ever declares a method in that way ...
Notice the member function is const. If such a function need return a
reference to a member of the object, it must return a const
reference, or use a const cast (or the member must be
mutable). That is:

struct Object
{
virtual Object*& at(int) = 0;
virtual const Object *const& at(long) const
{return other;} //Ok, other is const within const member
// function.

virtual Object *& wrong(long) const
{return other;} //Wrong, other is const within const member
// function, cannot be converted to Object*&.
private:
Object *other;
};
would it be that bad to
rephrase it into the form of the first method ?


Probably it would result in a compiler-error.
Jul 19 '05 #2

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

Similar topics

9
by: Michael Tobis | last post by:
Summary of my understanding of a recent interesting thread: General usage has "declaration" meaning "statement which does not generate executable bytecode but merely affects the compiler". My...
0
by: Rikard Land | last post by:
I try to model a data definition language in XML. It can be seen as C without any executable statements other than variable assignments. I want to allow for: (1) type declarations ("structs" in...
2
by: Chris Gordon-Smith | last post by:
I am currently in India and have treated myself to the Indian reprint of O'Reilly's "C++ In A Nutshell". (Books in India come in at 1/3 to 1/2 of the price in Britain.) I thought that I would...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
9
by: MLH | last post by:
Would the following work if placed in a form module rather than a global module? Declare Sub InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long)
14
by: Arthur J. O'Dwyer | last post by:
Well, I'm trying to write that program that was requested a few weeks back, the one that could take struct definitions and create portable functions to read and write those structs. Hence the...
28
by: Michael B. | last post by:
I tend to use rather descriptive names for parameters, so the old style of declaration appeals to me, as I can keep a declaration within 80 chars: void * newKlElem...
1
by: Chris | last post by:
This may be more of a Visual Studio question but those groups seem to be full of unrelated stuff so hopefully this might be the right place. I have a class (no associated aspx file) which handles...
10
by: Andy Fish | last post by:
hi, I have an XSLT which is producing XML output. many of the nodes in the output tree contain namespace declarations for namespaces that are used in the source document even though they are...
7
by: aspineux | last post by:
Hi I read the PEP 3117 about the new "Postfix type declarations" in Python3000. THIS PEP as been REJECTED ! But ... The notation in the PEP is very ugly ! This make python code more...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.