Mail Archives: djgpp/1995/07/26/13:18:59
Xref: | news-dnh.mv.net comp.os.msdos.djgpp:1173
|
Path: | news-dnh.mv.net!mv!news.sprintlink.net!hookup!news.kei.com!news.mathworks.com!gatech!news.uoregon.edu!news.rediris.es!diable.upc.es!diable!frankie
|
From: | frankie AT si DOT upc DOT es (Compte per el frankie)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: Help with classes!
|
Date: | 26 Jul 1995 11:52:23 GMT
|
Organization: | Serveis Informatics -- Universitat Politecnica de Catalunya
|
Lines: | 45
|
Distribution: | world
|
Reply-To: | frankie AT si DOT upc DOT es
|
Nntp-Posting-Host: | diable.upc.es
|
To: | djgpp AT sun DOT soe DOT clarkson DOT edu
|
Dj-Gateway: | from newsgroup comp.os.msdos.djgpp
|
In article 100000 AT athene, Ian Tester <94024831 AT athene DOT mit DOT csu DOT edu DOT au> () writes:
> hi,
> Sorry about this semi-djgpp content, but the c++ newsgroup is
> choka full of over 1500 messages, and I thought that my problem might be
> specific to djgpp.
> Anyway, I'm writting this 3D math library with classes for
> vectors, quaternions, and matrices. The vectors and quaternions work OK,
> but the matrix class doesn't. I'm pretty sure it's to do with the fact
> that the vec. and quat. classes don't have to allocate memory in their
> constructors. You see, in my matrix class, I have two ints which hold the
> number of rows and columns, and a 'float *' which will hold the array
> of elements. But to use it I have a constructor which takes the number of
> rows and columns to initialize it to, sets the two ints and allocates the
> memory with 'elements = new float[rows * cols]'. Is this right?
Yeah, this allocates memory for such a quantity of floats
> Anyway, in a little test program, I declare a matrix with
> 'Matrix M;', and then latter initialize it with 'M = Matrix(3,3);'.
> Is this right? Should I declare it as a pointer ?
>
> i.e 'Matrix *M;' and
> 'M = new Matrix(3,3);'
New returns a pointer for the new object it allocates memory for, so M gotta
be a pointer to Matrix, so declare it
Matrix *M;
> In the test program, it doesn't seem to set the two ints with the
> new size, so all other multiplications and stuff fail because its the
> wrong size.
Are you sure it doesn't ? And what's the answer of sizeof(elements) after
the new command has been done ?
> I would really like some help with this one. puh-lease!
I'm doing a try.
____________________________________________________________________________
Francesc Guasch Ortiz Universitat Politecnica de Catalunya
frankie AT si DOT upc DOT es Serveis Informatics
http://www.upc.es/~frankie
- Raw text -