[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] C++ spørgsmål - hvad gårgalt med minstring?



On Wed, 18 Apr 2001, Jonas Christian Drewsen wrote:

> > Hvis din instans af klassen ged, som ligger i (*i).first, er
> > af typen
> > "const ged", vil c++ kigge i klassen ged efter en function
> > der hedder
> > "string AsString() const".
> 
> Jeg har ikke skrevet const nogen steder omkring ged...
> 
> Er din iterator af typen const_iterator ?

Nej, det er den ikke. 
> 
> > Du har kun defineret en der hedder
> > "string
> > AsString()". Ved at sætte "const" efter
> > funktions-definitionen/-erklæringen angiver du at et objekt
> > af typen
> > ged, kan kalde denne funktion selv når objektet er const.
> 
> Men, hvad betyder det i denne sammenhæng at det er const?
> 
> Du fik i din fejlbesked:
> 
>  inputconsumer.cc:395: no matching function for call to
> `keyboard_inputevent_event_t::AsString () const'
>  inputkeyboard.hh:76: candidates are: class string
> keyboard_inputevent_event_t::AsString() <near match>
> 
> hvor første besked er, at den ikke kan finde en funktionen AsString der kan
> kaldes på et konstant objekt.
> Den anden besked er at du kan kalde AsString på et ikke konstant objekt.

Så langt var jeg med.

> 
> Dette betyder at dit objekt er konstant og du enten skal lave den ikke
> konstant eller skrive const efter funktionserklæringen, hvilket vel egentlig
> også er det pæneste da en AsString vel ikke ændre i objektet.

OK - det jeg ikke fattede var at det ikke var nok at skrive const _før_
funktionserklæringen. 

> Nej.
> 
> Det er nok lettere spotte fejlen hvis du sender lidt kildekode med.

Det virker nu, så jeg tror ikke jeg orker at isolere fejlen.

Tak for hjælpen.

Mads

-- 
Mads Bondo Dydensborg.                               sslug@sslug
ATA100 is another testimony to the fact that pigs can be made to fly given
sufficient thrust. 
                       - Linux kernel hacker Alan Cox, on IDE drives



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *