delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/22/11:43:52

From: "Campbell, Rolf [SKY:1U32:EXCH]" <moscoop AT americasm01 DOT nt DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Qualifiers
Date: Tue, 22 Feb 2000 10:58:09 -0500
Organization: Nortel Networks
Lines: 39
Message-ID: <38B2B211.A9B9D72E@americasm01.nt.com>
References: <200002211546 DOT HAA16127 AT www2 DOT xoommail DOT com>
NNTP-Posting-Host: wmerh0tk.ca.nortel.com
Mime-Version: 1.0
X-Mailer: Mozilla 4.72 [en] (X11; I; HP-UX B.10.20 9000/785)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Brian Ronk wrote:

> Ok, now that my timing problam is fixed, I've got
> a new one for you.  I can't figure out the error
> for the life of me.  I have an Array class, so I
> can get the size very easily, etc.  I used it
> inside another class, and wanted to use it in an
> ostream, so I could save the info.  My line is
> this:
>   int size=map.Links.Size();
> The error is this:
>   passing 'const Array<unsigned int>' as 'this'
> argument for 'int Array<unsigned int>::Size()'
> discards qualifiers
>
> Any ideas what I need to do to fix this?  Thanks
> again.

    Yes.

You need to add the 'const' qualifier to your 'Size' method.

int Array<T>::Size() const
{
  //body
}

What that does, is pass 'this' as 'Array<T>* const this' which means
that you will not be able to modify any class members in that function.


--
(\/) Rolf Campbell (\/)





- Raw text -


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