Solved

question about arrays and structs

Posted on 2000-04-25
5
221 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
port mapped I/o query 10 163
libcurl and C++ - Post JSON Data 8 1,178
how to understand recursion 12 218
An API detour question 7 79
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now