Thread: confused by two const decorationg: const vector<Object> const& getdata()

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    48

    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;
     }
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I take it what you are looking for is:
    const vector<TimePrice>& getdata() const
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

Tags for this Thread