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

trying to learn: const

what is the meaning of 2 *const* in following line?
-----------
const MyClass MyFunction const (MyClass &a);
-----------
Jul 19 '05 #1
3 1496
<- Chameleon -> wrote:
what is the meaning of 2 *const* in following line?
-----------
const MyClass MyFunction const (MyClass &a);
-----------


I suspect you mean somthing like this because what you have above is not
standard C++.

struct MyClass
{
const MyClass MyFunction (MyClass &a) const;
};
The first const is saying that the value returned is a const - i.e. it
may not be changed. The second const indicates the constness of "this".

Jul 19 '05 #2
<- Chameleon -> wrote:
what is the meaning of 2 *const* in following line?
-----------
const MyClass MyFunction const (MyClass &a);
-----------


Is that legal code? If it were

const MyClass* MyFunction( MyClass &a ) const;

the last const would mean that MyFunction can't change any of the fields
(member variables) of MyClass, and the first const would mean that
MyFunction returns a constant pointer to a MyClass object -- that is,
the returned pointer cannot be used to change what it points to.

For more info on const, look at
http://www.possibility.com/Cpp/const.html and
http://www.parashift.com/c++-faq-lit...rrectness.html

/ martin
Jul 19 '05 #3

"Martin Magnusson" <lo*******@frustratedhousewives.zzn.com> wrote in message news:bk**********@green.tninet.se...
<- Chameleon -> wrote:
what is the meaning of 2 *const* in following line?
-----------
const MyClass MyFunction const (MyClass &a);
-----------


Is that legal code? If it were

No. The last const after the function name is not allowed.
The first const is OK, but sort of spurious since the return
value usually gets copied anyhow, it will lose the constness.

Jul 19 '05 #4

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

Similar topics

55
by: Elijah | last post by:
I have read many of the topics on learning C++ or Java first. It seems like everyone says something different. I would like to know if I should learn C++ or Java. First a little about myself. I...
8
by: Rich Grise | last post by:
I think I've finally found a tutorial that can get me started: http://www.zib.de/Visual/people/mueller/Course/Tutorial/tutorial.html and I've been lurking for awhile as well. What happened is,...
5
by: winbatch | last post by:
Hi, I'm trying to write code such that my class can be used like so: To accomplish this, I'm trying to overload the + operator of my class to return a string. I am able to do this, but when I...
4
by: Deniz Bahar | last post by:
Hello, A couple days ago my friend (OOP guy) shows me what OOP was all about in C++. This morning I figured I can do pretty much the same thing with C (by putting function pointers in...
2
by: Stacey Levine | last post by:
I have been unsuccessfully trying to map network drives using user/password credentials. After spending lots of time looking around.. it seems like the way to go would be to use...
22
by: MLH | last post by:
I would like to test some of this code in the debug window... Option Compare Database Option Explicit Private Sub Command0_Click() #If Win32 Then MsgBox "Hey! It's WIN32." #End If End Sub
2
by: Frederick Gotham | last post by:
I'm going to be using an acronym a lot in this post: IINM = If I'm not mistaken Let's say we've got translation units which are going to be compiled to object files, and that these object...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
1
by: neisan | last post by:
Hi there, I'm trying for a while to obtain the XML content of a file without spaces. I have a XML file with the following content: <script> <command> <createDocument>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
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.