Article View: borland.public.jbuilder.java.language
Article #7992Re: How does a Java CLASS replace a C++ STRUCT?
From: Joi Ellis [TeamB]
Date: Mon, 07 May 2001 22:42
Date: Mon, 07 May 2001 22:42
45 lines
1988 bytes
1988 bytes
John Pruitt <john@branchsoft.com> wrote:
> 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++.
Java doesn't have structs. However, you can define a class SS and a class
Test like this:
public class ss {
private int sType;
private String sDesc;
private int sValue;
...
}
public class test {
int qType;
int qVers;
int qMem;
ss[] ssList = new ss[10];
int qfinal;
...
}
*Not tested, I'm not certain I got the array definition syntax correct*
--
Joi Ellis (TeamB)
No direct email, please.
For best results, post on news server newsgroups.borland.com!
Newsgroup Info: http://www.borland.com/newsgroups/guide.html
Technical Details
Message-ID:
<3af724cb_1@dnews>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!212.74.64.35!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews!not-for-mailReferences:
<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 16:12:04 PST
Message-ID: <3af724cb_1@dnews>
From: "Joi Ellis [TeamB]" <joi@aravox.com>
Subject: Re: How does a Java CLASS replace a C++ STRUCT?
Newsgroups: borland.public.jbuilder.java.language
References: <3af6dd31$1_2@dnews>
User-Agent: tin/1.4.2-20000205 ("Possession") (UNIX) (Linux/2.2.16-3 (i686))
NNTP-Posting-Host: 209.46.41.66
Date: 7 May 2001 15:42:19 -0700
X-Trace: dnews 989275339 209.46.41.66 (7 May 2001 15:42:19 -0700)
Lines: 45
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!212.74.64.35!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews!not-for-mail