hi,
I have stored instances of class A
in a std:vector
, vec_A
as vec_A.push_back(A(i))
. The code is shown below.
Now, I want to store references some of the instances of class A
(in vec_A
) in another vector or another array. For example, if the A.getNumber()
returns 4, 7, 2 , I want to store a pointer to that instance of A in another vector, say std:vector<A*> filtered_A
or an array.
Can someone sow me how to do this?? Thanks!
class A {
public:
int getNumber();
A(int val);
~A(){};
private:
int num;
};
A::A(int val){
num = val;
};
int A::getNumber(){
return num;
};
int main(){
int i =0;
int num;
std::vector<A> vec_A;
for ( i = 0; i < 10; i++){
vec_A.push_back(A(i));
}
std::cout << "\nPress RETURN to continue...";
std::cin.get();
return 0;
}