obviously its not real code. its meant to describe what i am trying to do. let me ask this? if i a fill a vector in one function, and that vector is declared in the header file, will that filled vector be able to be read by other member functions? i don't want to have to return it, or pass it in parameter. i want to set it once, the computation is to expensive to keep doing and returning.
¿how is the vector declared?
If it is a member variable, all member functions may access it
If it is a static member variable, all member functions from all the objects of that class may access it
If it is global, all can access it.
hey thanks. the vector is declared in the private section of the header file.
1 2 3 4 5 6 7 8 9 10 11
class child : public parent
{
public:
//functions declared here
protected:
//functions declared here
private:
//functions declared here
//vector declared here
}
so once the vector is filled, all the other functions can read the contents of that vector?
It's declared as a private member - as is usually correct for class data members - so it is visible only to other methods of the class.
If any code outside the class needs to access the contents of the vector, you'll need to pass it via a public method. When doing so, you'll need to consider whether you're passing a copy of the vector, or a reference/pointer to the actual data member, considering issues such as separation of interface and implementation, ownership of data, and the lifetime of the class and the validity of those pointers/references.