delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/04/15:34:04

From: abarak AT iil DOT intel DOT com (Amit Barak)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A question about C++ language!
Date: 4 Aug 1997 09:51:54 GMT
Organization: Intel Israel (74) Ltd.
Lines: 49
Message-ID: <5s48nq$14hg$1@ilnews.iil.intel.com>
References: <33E3ADA9 DOT D59DD86C AT mailhost DOT tcs DOT tulane DOT edu>
NNTP-Posting-Host: ilx214.iil.intel.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

in general 'const' methods are declared and defined using
the keyword 'const' after the arguments list, just like in
'double g() const' you posted.

const functions (methods) are not allowed to modify values
of object's data members, and may only call const methods.

however, i am not sure how the ambiguity between the two
g() methods ('const' and non-const) is resolved if you do
this -

int main()
{
 B b;

  cout << b.g() << endl;

  return 0;
}

??


Tianmiao Hu Family (thu AT mailhost DOT tcs DOT tulane DOT edu) wrote:
: Hello,
: 
: What does "double g() const;" line in the following code mean? Is it
: different from the next line "double g();"? This is an example from a
: book called "Scientific and Engineering C++:
:    An Introduction with Advanced Techniques and Examples". I have tried
: to compile it under DJGPP and it passed. I don't understand why "const"
: can appear after "g()"?
: 
: 
: class B {
:     double g() const;
:     double g();
:     double g(int);
:     void h();
: };
: 
: Thank you for your great help!
: 
: Tianmiao Hu
: 

-- 
 amit barak

- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019