I am newbie to c++.I have created two classes.one class(say A) will push the struct data into vector while other class(say B) will pop out the data from the vector.
How do I pass the reference of vector from class A to B so that class B can point to same vector object to pop out data,to do some manipulation.
can anyone help me to resolve this
So far My effort is, A.h file:
struct strctOfA {
       int x;
       int y;
       int z;
    };  
class A {
public:
A();        
private:
     std::vector<strctOfA> t2;
};
    A.cpp file:
    <pre><code>
         A::A() {
        strctOfA player;
        player.x=1;
        player.y=2;
        player.z=3;
        t2.push_back(player)
        B b;
        b.functionOfB(&t2); 
        }
    B.h file
    <pre><code>
         class B {
        public:
             B();
             functionOfB(&t2);
        };
 B.cpp:
 B::functionOfB(A &t) {
    t2.pop_front(); 
    }
Aucun commentaire:
Enregistrer un commentaire