[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] compiler bug?



Sune Fischer wrote:
> Det forstår jeg ikke. Hvad skulle forskellen være på:
Et forslag:

> CMatrix CMatrix::operator*(CMatrix& A)
> {
>   CMatrix R;
:
> return R;
> }

Har du husket at definere en copy funktion for matrixer?
Dvs. CMatrix CMatrix::operator=(CMatrix& A)?

Der der sker er:
> CMatrix CMatrix::operator*(CMatrix& A)
> {
>   CMatrix R;
Her kaldes constructoren for at lave en matrix.
(Jeg formoder at du har lavet det så den ved hvor
 stor den skal være.)

:

> return R;
Her returnere du R til resten af programmet. Men i slutningen 
af af R's scope kalder compileren automatisk R's deconstructor.
> }

Så den variabel du har tilknyttet R er muligvis en matrix
hvis hukommelse m.m. allerede er dealloceret fordi dens
dekonstructor er blevet kaldt på dette tidspunkt.

Prøv at indsætte cout << "CMatrix::method\n"; i alle dine
matrix funktioner og se hvilke funktioner, konstructorer og
dekonstruktorer der kaldes hvornår.

Husk at A=B*C for matrixer i virkeligheden er
  A.operator=(B.operator*(C))

Og hvis du kører koden skulle du se noget som:

   B.operator*(C)
R: CMatrix::constructor
A: CMatrix::constructor
A: CMatrix::operator=
R: CMatrix::~deconstructor

Eller noget i den stil.

-- 
	Sometimes it's better to light a       Carsten Svaneborg
      flamethrower than curse the darkness.      sslug@sslug
	-- (Terry Pratchett, Men At Arms)    Fight Bill - use Linux


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