TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: David Nugent
from: Roy McNeill
date: 1995-08-11 23:56:02
subject: problem in c++

Hi David



 > GC> x=new unit[]={...};



 RM> The above line won't work because you're trying to initialize a

 RM> pointer, not a structure. The line



 DN> ??



It's the 2nd part of the statement I was pointing out, the "={...}"

bit. He's trying to initialize a pointer with structure data,

without dereferencing the pointer.



{

 Btw, I'm not strong on multiple equal statements like that. I

 know that



  int i=1, j=2, k=3;

  i=j=k;



 makes i,j,k all equal to 3. But I'm not certain exactly what

 happens in what order. Could get very confusing if more

 complicated.

}



 RM> The fact that you have the structure inside a class only

 RM> complicates things; the real problem is your attempting to

 RM> initialize a pointer with structure contents.



 DN> C++ can handle this situation just fine.



yes, but if you stuff up somewhere, the compiler may sometimes

give an error msg about a class violation or similar, rather than a

more accurate msg that you'd get outside the class.





Probably the answer I should have given Griffon is something like



 // In the class definition, set up y as a data member

 unit *y;



 // Somewhere else, point y at a new unit and initialize it

 y = new unit ['c',1];

 // and don't forget to delete(y) before the class disappears...



Hope he's still listening.



Cheers



--- PPoint 1.88


* Origin: Silicon Heaven (3:711/934.16)
SEEN-BY: 711/809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.