Solved

question about arrays and structs

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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 pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

707 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

11 Experts available now in Live!

Get 1:1 Help Now