954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

passing one vector to another classes vector

Having trouble trying to copy the vector 'sel' in main to vector 'ask' in class A.

Can someone either explain or show me?

Thanks in Advance!

class A{
private:
        
public:
vector<Trader> ask;
 void AskMatchList(vector<Trader>&);
  void showAuct();
};
void A::AskMatchList(vector<Trader> &list){
     vector<Trader>::iterator it;
     f1= new Trader; //I understand this is the WRONG WAY
     f1->BidId;      //but dont know the correct way....  :(
     f1->TraderId;
     f1->type;
     f1->quantity;
     f1->price;
     }
void A::showAuct(){
     vector<Trader>::iterator it;
     for(it=ask.begin();it!=ask.end();++it){
     it->showTrader();
     }
}   

    
     int main(){
  srand ( time(NULL) );    
  vector<Trader> sel;
  vector<Trader> buy;
  vector<Trader>::iterator it;
  A auct;

int x = 0;
    Trader* seller= new Trader[(NUMSELLER*NUMBIDS)];
    Trader* buyer= new Trader[(NUMBUYER*NUMBIDS)];
    
    //code to set the BidId,TraderId, Type, Quantity, Price
    //for sel
 
auct.AskMatchList(sel);//Suppose to copy from vector<Trader> sel TO Auctioneer classes vector

auct.showAuct();

system("pause");
return 0;
}
prototyppe
Newbie Poster
7 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

OKAY!!! Sorry about this people. But I found out like 10 minutes later how to do it (just by googling my title funny enough)

The way to pass one vector from one class to another class is done on this website:

http://stackoverflow.com/questions/644673/fast-way-to-copy-one-vector-into-another

OR (from that above site):
I USE THIS ONE!!!(but altered it for my use)

void copyVecFast(const vec<int>& original)
{
  vector<int> newVec;
  newVec.reserve(original.size());
  copy(original.begin(),original.end(),back_inserter(newVec));
}
prototyppe
Newbie Poster
7 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: