[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] Men ett vanligt konstruktoranrop då?



"Jonny Andersson" <sslug@sslug> writes:
> Jag konstaterade precis som dig att man inte kan anropa en
> konstruktor i den egna klassen genom ett anrop från
> konstruktorinitialiseringslistan utan man kan bara anropa en
> konstruktor i en basklass den vägen tydligen.  Däremot kan du göra
> ett normal konstruktoranrop (måste då vara det första du gör i den
> konstruktor som anropar) så här:

Jeg begyndte også at lege med det program du beskriver. Det ser smukt
ud og det compiler fint, men da jeg prøvede det af virkede det ikke
. Problemet er at constructeren A(double) opretter en navnløs lokal
variabel af typen A. Linien this->i = i retter kun i den lokale
variabel.

> class A {
> public:
>   A( int i ) {
>     this->i = i;
>   } // constr.
> 
>   A( double d ) {

Den følgende ordre opretter en navnløs lokal variabel.

>     A( 2 );      

Når du er nået hertil er this->i ikke 2.

>     // i = 2;
>     this->d = d;
>   } // constr.
> private:
>   int i;
>   double d;
> }; // A

-- 
Niels L Ellegaard  http://dirac.ruc.dk/~gnalle/
SPECIAL OFFER! I proofread unsolicited commercial email sent to this
address at a rate of US $500.00 per incident!  Include billing address
in your message and save US $500.00 per hour off ordinary address
resolution and tracking charge!


 
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] *