Setting class members

This is a discussion on Setting class members within the C++ Programming forums, part of the General Programming Boards category; Is there a short/quicker way to set class member except using the normal way..? Code: void SetDate(tm curr_tm) { day ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Setting class members

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

    Code:
    	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
    Location
    Singapore
    Posts
    20,968
    I do not think so, but perhaps you are thinking of an initialisation list, but that is only applicable in a constructor.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    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, 02:50 PM

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