access class member from different class

I want to manipulate a class member from several other classes.
class A
1
2
3
4
5
6
7
class A  //"classA.h"
{
public:
   void sum();   //sum the elements vector
   void push() //push element to the vector
   vector<int> test;
};


class B
1
2
3
4
5
6
7
8
9
10
11
#include "classA.h"
class B
{
public:
   void pushToVector(int a)
   {
     //the obviou is to create an object of class A
     class A obj; 
     obj.push(int);
   }
};


class C
1
2
3
4
5
6
7
8
9
10
#include "classA.h"
class C 
{
public:
  void sumVector()
  {
      class A obj;
      obj.sum();
   }
};


The problem is this.
When ever class B::pushToVector(int) is called, obj is reconstructed with a new vector. Hence, only 1 element is in obj.vector after every call to pushToVector from class B.

When ever class C::sumVector() is called, obj is reconstructed. the value return by the sum of the vector obj.test is always 0.

Moreover, even if classB::pushToVector(int) worked well as not to reconstruct obj every time, its a different obj that is in class C.

How do i then make this manipulations for the respective calls to classB::pushVector(int) and class C::sum to manipulate on a single classA::obj that does not reconstruct every time.
Make it a member of class instead of local variable inside of class method.
Topic archived. No new replies allowed.