473,387 Members | 1,574 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,387 software developers and data experts.

const objects ->const member functions?

I am just curious: if you declare an object constant - can it call NOT
constant member functions of the class or only constant ones?
are there generic rules for such objects?
THANKs

Jul 23 '05 #1
2 1199
puzzlecracker wrote:
I am just curious: if you declare an object constant - can it call NOT
constant member functions of the class or only constant ones?
I believe only const member functions may be called on a const object.

are there generic rules for such objects?


const objects are meant to be non-changing. A function that will not
alter the instance it is operating on should be labeled as const to
represent this fact. Member functions that do change the internals of
their instances must not be used on an object that is not supposed to
change.

It is pretty straight forward if you keep in mind what 'const' means.
It means 'constant'.

Hope that helps.
Jul 23 '05 #2
"puzzlecracker" <ir*********@gmail.com> wrote in message
I am just curious: if you declare an object constant - can it call NOT
constant member functions of the class or only constant ones?
It can only call constant ones.
are there generic rules for such objects?


What do you mean?
Jul 23 '05 #3

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

Similar topics

6
by: cppsks | last post by:
What would be the rational for using const with standard types? const int & OR const unsigned long & Thanks.
8
by: Derek | last post by:
Some authors advocate returning const objects: const Point operator+(const Point&, const Point&); ^^^^^ Returning a const object prevents some bad code from compiling: Point a, b, c; (a +...
10
by: ATASLO | last post by:
In the following example, section #3 fails under VC98, VC2003, VC2005 Express Beta (Aug 2004) and g++ 3.3.2. Is this just a pitfall of the C++ specification? Why don't any of the above compilers...
2
by: vineoff | last post by:
When you should not or can't use const references? Like void f ( const Foo& b) ; or int main() { const int& r = 5; }
2
by: Scott Brown | last post by:
Hi, I'm new to this list. I have looked around the archives for this question but haven't seen an answer for it yet (though there are a lot of messages to sift through). Say I'm operating...
3
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static...
41
by: Serve Laurijssen | last post by:
Theres a certain style of coding that uses const as much as possible. Like const int foo(const int a, const int b) { const int retval = pow(a, b); return retval; } one argument to use code...
6
by: Hubert Fritz | last post by:
Hello, I fear I want to have something which is not possible in C++. How is it possible to define a base class so that the derived class is forced to contain a static member variable, which...
5
by: coolguyaroundyou | last post by:
Consider the following codes: class abc { int i; public: abc() : i(0) {} void func() { .....some code....} };
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.