C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-03-2009, 08:50 AM   #1
Registered User
 
Join Date: Dec 2008
Posts: 41
confused by two const decorationg: const vector<Object> const& getdata()

Hey, there, I have this class written several months ago when I had a reference book at hand, and pretty much imitated it. Now I cannot figure out the definition of getdata() anymore, and cannot find the reference neither. Please explain to me how to define getdata() such that it won't modify data itself, and it returns a const reference to the data, such that caller will not change data as well. Does the current definition meet the requirement? Thanks!
Code:
class Log{
private:
  string name;
  vector<TimePrice> data;
...
public:
  vector<TimePrice> const& getdata(){
  return data;
 }
}
patiobarbecue is offline   Reply With Quote
Old 04-03-2009, 08:52 AM   #2
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
I take it what you are looking for is:
const vector<TimePrice>& getdata() const
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Tags
const, return reference

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Function template has already been defined Elysia C++ Programming 19 04-14-2009 10:17 AM
The so annoying LNK2005... please help! Mikey_S C++ Programming 14 02-01-2009 04:22 AM
Undefined Reference Compiling Error AlakaAlaki C++ Programming 1 06-27-2008 11:45 AM
Including lib in a lib bibiteinfo C++ Programming 0 02-07-2006 02:28 PM
oh me oh my hash maps up the wazoo DarkDays C++ Programming 5 11-30-2001 12:54 PM


All times are GMT -6. The time now is 07:07 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22