Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 05-02-2005, 02:03 AM   #1 (permalink)
lostromos
Registered User
 
Join Date: Apr 2005
Posts: 5
lostromos is on a distinguished road
Const functions returning const

Hello all,

const int function() const;

This function returns a const int. I'm ok with that. What's the use of the second "const"? I didnt find the answer in standard C/C++ manuals, so i felt the need to disturb you one more.

Thanks a lot in advance
lostromos is offline   Reply With Quote
Old 05-02-2005, 03:56 AM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
It means that the function function() is not allowed to modify any members.
Code:
class ConstTest
{
public:
   string a_;
   void print() const
   {
      a_ =  "Hi Iostromos!"; //ILLEGAL. const qualifier forbids modifying members.
      std::cout<<"a_"<<std::endl;
   }
};
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
dBase functions in PC based PHP? Wysocki PHP 1 02-11-2005 12:49 PM
hashing help saiz66 Standard C, C++ 2 06-28-2004 02:39 AM
I'm having some problems with inheritance... <-- newb mik0rs Standard C, C++ 5 04-08-2003 11:54 PM
returning functions sde PHP 1 12-18-2002 03:14 AM


All times are GMT -8. The time now is 08:06 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting