Link to home
Start Free TrialLog in
Avatar of beachbumm
beachbumm

asked on

question about arrays and structs

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
Avatar of Jmccp
Jmccp

<< 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
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
Avatar of beachbumm

ASKER

so what you are saying is that arrays and structs are combined or are they redefined in the declarations of class attributes?
see above comment...
ASKER CERTIFIED SOLUTION
Avatar of ntdragon
ntdragon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial