private vector

I keep trying to pass a private vector from a class to an other,
but still doesn't work even as a Friend class.
How can i do
Last edited on
Hi,
Show the code please .. it easier to get the problem then.
Was you looking for something like this ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <vector>

using namespace std;

class myclass0 {
private:
    vector<int> myvector;
public:
    const vector<int>& getvector() const {return myvector;}
    void setvector(vector<int> vec){myvector = vec;}
}class0;

class myclass1 {
private:
    vector<int> myvector;
public:
    const vector<int>& getvector() const {return myvector;}
    void setvector(vector<int> vec){myvector = vec;}
}class1;

int main()
{
    class0.setvector(class1.getvector());
    cout << "Hello world!" << endl;
    return 0;
}
Hi, thank you for answering.
The think is that i have to make a vector of class !
I know how to use a string (or a regular variable) on a vector.
but i am having a crazy time trying to use it on a vector of class
but i am having a crazy time trying to use it on a vector of class

std::string is a class. Using your own class is no different.
1
2
  vector<string>  v_string;
  vector<myclass> v_myclass;


Topic archived. No new replies allowed.