TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Roy McNeill
from: David Nugent
date: 1995-08-13 16:15:44
subject: problem in c++

> > 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.


Ok.


 > 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.

Indeed. Error parsing is difficult at best, and tricky as hell to get
right. :-) C++ is not an easy language to parse.


 > 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...

This won't work either.

What you'd need to do is to define a constructor for class/struct unit
which takes the correct arguments.


  David

---
* Origin: Unique Computing, Melbourne, Australia (3:632/348)
SEEN-BY: 50/99 620/243 623/630 632/103 348 998 633/371 634/384 388 635/301
SEEN-BY: 502 503 544 727 636/100 639/100 711/401 409 410 430 510 807 808 809
SEEN-BY: 932 934 712/515 713/888 714/906 800/1 7877/2809
@PATH: 632/103 348 635/503 50/99 711/808 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™.