tags:

views:

79

answers:

2

Assume that int array arrayName is a member of class className, How can I access its element in my main program?? className.arrayName[0] doesn't seem to work

+3  A: 

It should be objectName.arrayName[index], where objectName is an instance of your class. Don't forget to declare your arrayName public.

(Assuming that your arrayName is not static.)

Vlad
+8  A: 

If arrayName is static inside class className, then you can access it like that:

//Declaration
class className{
public: 
  static int arrayName[5];
};

//Access
className::arrayName[index];

If it is not static, you must create an instance of your class first.

//Declaration
class className{
public: 
  int arrayName[5];
};

//Access
className a;
a.arrayName[index];
Draco Ater