943,650 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 533
  • C++ RSS
Jun 24th, 2009
0

Can I return Vector from Virtual Function

Expand Post »
Hi,

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

C++ Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Niner710 is offline Offline
31 posts
since Jul 2008
Jun 24th, 2009
0

Re: Can I return Vector from Virtual Function

misspellings mostly
C++ Syntax (Toggle Plain Text)
  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. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,949 posts
since Aug 2005
Jun 25th, 2009
1

Re: Can I return Vector from Virtual Function

I prefer

C++ Syntax (Toggle Plain Text)
  1. void A::getSomeStuff(vector<int> & vec)
  2. {
  3. ...
  4. }

to avoid a possible copy on return.
Reputation Points: 395
Solved Threads: 71
Posting Whiz
jencas is offline Offline
362 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Good and Bad Habits?
Next Thread in C++ Forum Timeline: No error But wrong Output. Why??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC