Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function structure

Status
Not open for further replies.

gmgarrison

Programmer
Sep 26, 2000
11
0
0
US

If I have a function defition written thus:

returntype functionname(paramtype paramname) : type(var) { }

what's the significance of the ": type(var)?" i guess i don't know what the colon operator does in that conext. thanks for the help!!
 
Dear gmgarrison,

> If I have a function defition written thus:

Stricktly speaking I believe you are asking about a 'constructor', not a 'function'.

> i guess i don't know what the colon operator does in that conext

It denotes the 'initialization list'. This is where members of the class can be initialized during object construction. This includes any base classes that the class is derived from, i.e.

class foo{
int _fooval;
public:
foo( int n){
_fooval = n;
}
};

class fooEx : public foo{
public:
// use initialization list to pass the value of x to the
// 'foo' constructor
fooEx(int x) : foo(x){}
};

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top