Solved

question about arrays and structs

Posted on 2000-04-25
5
234 Views
Last Modified: 2012-05-04
Can arrays and structs be used in the declarations of class attributes? if so are they combined or redifined? i was told in C++ you no longer need to use typedef name for a structure or use the struct keyword. any help on this would be appreciated! thanks in advance
0
Comment
Question by:beachbumm
  • 2
  • 2
5 Comments
 
LVL 1

Expert Comment

by:Jmccp
ID: 2749274
<< Can arrays and structs be used in the declarations of class attributes? >>

Yes they can.  Say you have a structure:

struct struct1
{
   char abc[10];
   int def;
   long ghi;
};


Now in a class declaration below:

class class1
{
   char string1[20];
   struct1 aStructvar;
}

Here we have a class called class1 that consists of a character array and another struct.  You reference the above array as follows:

class1 classVar;
classVar.struct1.abc[0] = '\0';
classVar.struct1.def = 150;
classVar.struct1.ghi = 233124;
class1.string1[0] = '\0';

-Jim
0
 
LVL 1

Expert Comment

by:ntdragon
ID: 2749275
in c++ you don't use structs you use class

it's alot better with some intersting and usefull opetions

but ofcourse you can use arrays and structs in class's you even can make class's in other class's

do you want to how anything else
0
 

Author Comment

by:beachbumm
ID: 2751284
so what you are saying is that arrays and structs are combined or are they redefined in the declarations of class attributes?
0
 

Author Comment

by:beachbumm
ID: 2751363
see above comment...
0
 
LVL 1

Accepted Solution

by:
ntdragon earned 10 total points
ID: 2752399
what i'm saying is you can and may use them together but if you use classes you don't need structs

<or i really didn't understood your question>
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question