Can I return Vector from Virtual Function

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2008
Posts: 25
Reputation: Niner710 is an unknown quantity at this point 
Solved Threads: 0
Niner710 Niner710 is offline Offline
Light Poster

Can I return Vector from Virtual Function

 
0
  #1
Jun 24th, 2009
Hi,

I was curious if I could return a vector from a virtual function. I keep getting an error for this.

  1. Class A
  2. {
  3. public:
  4. virtual vector<int> getSomeStuff();
  5. private:
  6. }
  7.  
  8. .cpp File
  9. vector<int> A::getsomeStuff()
  10. {
  11. return;
  12. }

Can anyone tell me what I am doing wrong?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,639
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1497
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Can I return Vector from Virtual Function

 
0
  #2
Jun 24th, 2009
misspellings mostly
  1. class A
  2. {
  3. public:
  4. virtual vector<int> getSomeStuff();
  5. private:
  6. };
  7.  
  8.  
  9. vector<int> A::getSomeStuff()
  10. {
  11. vector<int> ay;
  12. return ay;
  13. }
  14.  
  15. int main()
  16. {
  17. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Can I return Vector from Virtual Function

 
1
  #3
Jun 25th, 2009
I prefer

  1. void A::getSomeStuff(vector<int> & vec)
  2. {
  3. ...
  4. }

to avoid a possible copy on return.
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 286 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC