Vector passing from one class to another

So, I have a question.

Let's say I have a vectorA (any vector) in Class A. I initialized it in ClassA.h, and declared the vectorA in ClassA.cpp

I have to add an value to vectorA through another class, ClassB. How do I do this? Do I use pointers? I am really lost.

Not really the exact code, but I wanted to be more detailed.

ClassA::ClassA {

//Constructor
vector <string> VectorA;

}


ClassB::ClassB {

//nothing

}

How can I change vectorA in classB?
Last edited on
If you can post the actual code we may be able to provide a better answer.

But from what I understand of your question, you can solve this by passing an object of type ClassB to the ClassA function that adds values to VectorA. The function would take whatever field it needs from the ClassB object (by calling a getter), and add it to VectorA.
Or you can make a class B method a friend of class A. 2 things to bear in mind:
a. forward declaration of B before A
b. the friend function should take as argument class A object as non const reference
Topic archived. No new replies allowed.