views:

122

answers:

3

I have created an array in the implementation of my class loginController. Now I want to use this array (with its objects) in another class of my project. What is the right way to import it?

A: 

You really need to specify the language.

In general, if the array is a member variable in one class, it's considered bad form to directly use it from another class. This violates the "encapsulation" idea that is quite the thing in object-oriented programming.

The preferred thing to do is often to add methods, called "getters" and "setters", to the class owning the array, or make it available by some other more structural means, which depend on the exact semantics and usage of the array. It might, for instance, not be required that outside users even know that it is an array.

unwind
A: 

There is no right way given this information. What is located in the array, only integers or strings/objects etc. Do you store objects of pointers to objects?

Passing the array is the sameway as passing any other object to a function

PoweRoy
A: 

The general answer would be: declare it as public

It is not very good thing to do but as a beginner, you can start with that.

Josef Sábl