Thread: Setting class members

  1. #1
    Registered User
    Join Date
    Apr 2008

    Setting class members

    Is there a short/quicker way to set class member except using the normal way..?

    	void SetDate(tm curr_tm)
    		day = curr_tm.tm_mday;
    		month = curr_tm.tm_mon;
    		year = curr_tm.tm_year;
    		hour = curr_tm.tm_hour;
    		minute = curr_tm.tm_min;
    		local_dt = curr_tm;
    Someone mentioned this but can't remember

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    I do not think so, but perhaps you are thinking of an initialisation list, but that is only applicable in a constructor.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Why don't you just encapulate the tm struct/class in your class instead of breaking out all the elements? The tm's copy constructor would take care of the copying for you if all of the members have well-defined copy semantics, and if they're just ints and longs, they do.
    Last edited by medievalelks; 07-28-2008 at 06:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking error with static template class members
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 04-02-2009, 12:31 PM
  2. returning class and struct members
    By simone.marras in forum C++ Programming
    Replies: 17
    Last Post: 03-16-2009, 11:10 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Inheiritance and derived classes
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2001, 03:50 PM