Skip to main content
gamedev.net
🔒 Locked

C++ question

Started by KlDzny Nov 24, 2000 at 3:36 AM 2 replies 400+ views
Original Post
KlDzny
KlDzny
Right, what does this mean (it''s just an example): int someclass::somefunction(int some, char* variables) : someother(char* crap) { . . . return 1; } I know the int someclass::somefunction(int some, char* variables), that''s pretty self explanatory, what is the : someother(char* crap) in aid of? Please help me, I''m not totally new to C++, just never seen this until today... Thanks in advance "Success can make you persevere for hours, failure can make you quit in seconds" - KlDzny
"Success can make you persevere for hours, failure can make you quit in seconds" - KlDzny
Ksero
Ksero
I''ve only seen (and sometimes used) it used in constructors, like this:
  
Cderived::Cderived(int some, char* something) : CBase(some)
{
}

This means that the CBase constructor will be called before executing the CDerived constructor.
Zeke
Zeke
Its an explicit function call. if you have more than one somefunction(int some, char* variables) then you might need to add the : someother(char* crap) so that the right somefunction is called. At least i think thats what it is.


"People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face

Edited by - Zeke on November 24, 2000 11:37:10 AM
Just my thoughts take them as you will. "People spend too much time thinking about the past, whatever else it is, its gone"-Mel Gibson, Man Without A Face
Teej
Teej
It doesn''t matter that it''s a derived class. In general, any other constructors you''d like called (or values assigned to any variables) can go there.

  
class CExample
{
public:
CExample();
CExample(int a, int b) : m_myA(a), m_myB(b) {};

private:
int m_myA;
int m_myB;
};


This will assign a and b to m_myA and m_myB, respectively. I think that the only reason why one would use this method over performing the assignment in the body of the function is that there might be a precompiled header issue...

Teej

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.