How to pass a data member by reference from main?

closed account (N8RzwA7f)


So , I'm not sure how to do this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// class.cpp
class A  {
   public:
      void myFunct(vector <int>& myvect);
   protected:
      vector <int> myvect;
   ...
} 
class B : public A {
   public:
      void myFunct(vector <int>& myvect);
   ...
} 

...
int main( ) {
   B newB;
   newB.myFunct(//not sure how to do this) ;
}
It's very unclear what you're trying to do from the generic names, poor description and uncompilable code. Perhaps you could provide a little more context.
Last edited on
closed account (N8RzwA7f)
There's a vector in a base class that I'm passing by reference to a function (myFunct) in a derived class, and I need to call this derived function (myFunct) from main ? But it's not possible to access the same myvect from main. So do I just create a new vector in main and pass that by reference ?

thanks.
If the vector is a member of A, it is also a member of B. Why does your instance of B need to be passed a reference to something it owns?
Topic archived. No new replies allowed.