4 Replies - 275 Views - Last Post: 10 October 2012 - 12:55 PM Rate Topic: -----

#1 Flickayy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-August 12

C++ Constructors

Posted 09 October 2012 - 08:54 AM

Hey DIC, I have a small question about Constructors in C++.

I understand the basics of the constructor & destructor, but when I was looking over some source code, I have seen a constructor used in a way I've never seen before, so I was hoping someone could either point me in the right direction so I can read up on this specific way of using it.

Here is the constructor that has puzzled me for awhile.
 IEntity(const typeEntityID theID, App* theApp) :
mApp(theApp),
mID(theID),
mInit(false),
mPaused(false),
mCleanup(false),
mElapsedTime(0.0f),
mPausedTime(0.0f)
{
	    
}



What is the purpose for the ":" in this constructor? Thanks for the help in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: C++ Constructors

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,569
  • Joined: 25-December 09

Re: C++ Constructors

Posted 09 October 2012 - 08:58 AM

The colon signifies the start of the initialization list. It means that the class member variables that follow will be initialized to the value provided inside the parentheses.

Jim

This post has been edited by jimblumberg: 09 October 2012 - 08:58 AM

Was This Post Helpful? 1
  • +
  • -

#3 Flickayy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-August 12

Re: C++ Constructors

Posted 09 October 2012 - 09:04 AM

Ah I see, that makes sense now.

Thank you for the quick reply and for providing a link, that has definitely cleared some issues up.

^_^
Was This Post Helpful? 0
  • +
  • -

#4 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: C++ Constructors

Posted 09 October 2012 - 12:57 PM

Well said by jimblumberg... Initialization lists are very useful and are good to use always. Even they are must to use and the only option when you deal with const and references in your class which need to be initialized and assigned a value, which cannot be done in constructor's body... This way the constructor assigns the values through implicit initialization...

Here is a small and very well written article you have to read....

Hope this Helps!
Was This Post Helpful? 1
  • +
  • -

#5 Flickayy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 12-August 12

Re: C++ Constructors

Posted 10 October 2012 - 12:55 PM

@AKMafia001

Thank you for the link, I've been reading through the tutorials on that site a very useful resource, so thank you! ^_^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1