Article View: borland.public.jbuilder.java.language
Article #7991Re: How does a Java CLASS replace a C++ STRUCT?
From: Dave Bird
Date: Mon, 07 May 2001 18:15
Date: Mon, 07 May 2001 18:15
48 lines
2281 bytes
2281 bytes
In article <3af6dd31$1_2@dnews>, John Pruitt <john@branchsoft.com>
writes
>Can someone please explain how a Java class replaces a C++ struct when it comes
>to complex data structures.
>ie:
> struct test {
> int qType;
> int qVers;
> int qMem;
> struct {
> char sType;
> char sDesc[17];
> int sValue;
> } ss[10];
> int qfinal;
> };
>
>I've tried every way I can think of to use a class instead of a struct,
>but can't find any way to define an array of [10] class "ss" within
>class "test" and actually make it work the same as a stuct within a
>struct does in C++.
Try not to have nameless classes, though they can be used in some
contexts. Try:
> class Test { public:
> int qType;
> int qVers;
> int qMem;
> class TPart { public:
> char sType;
> char sDesc[17];
> int sValue;
> TPart(){ sValue=0; sType=0; sDesc[0]=0; };
> };
> TPart ss[10] = new TPart[10]();
> int qfinal;
> };
If that doesn't work then declare TPart separately.
Making everything public is not very Java-ish though.
--
^-^-^-@@-^-;-^ http://www.xemu.demon.co.uk/
(..)__u news:alt.smoking.mooses
happy as a clam at high tide -. <_" .-._.-.
Technical Details
Message-ID:
<IITQXBHZZu96Ew5I@xemu.demon.co.uk>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!daveReferences:
<3af6dd31$1_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,f48c7921166a8f24 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-05-07 13:08:03 PST Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!dispose.news.demon.net!news.demon.co.uk!demon!xemu.demon.co.uk!dave From: Dave Bird <dave@xemu.demon.co.uk> Newsgroups: borland.public.jbuilder.java.language Subject: Re: How does a Java CLASS replace a C++ STRUCT? Date: Mon, 7 May 2001 19:15:53 +0100 Organization: none Message-ID: <IITQXBHZZu96Ew5I@xemu.demon.co.uk> References: <3af6dd31$1_2@dnews> NNTP-Posting-Host: xemu.demon.co.uk X-NNTP-Posting-Host: xemu.demon.co.uk:158.152.196.209 X-Trace: news.demon.co.uk 989265316 nnrp-01:9230 NO-IDENT xemu.demon.co.uk:158.152.196.209 X-Complaints-To: abuse@demon.net MIME-Version: 1.0 X-Newsreader: Turnpike Integrated Version 5.00 U <dQumtnY$x4rJ2u5tL5fS$n2vuP> Lines: 49