PDA

View Full Version : re: defining variables when set to a value?


darktding
12-30-2006, 03:17 PM
Recently I came across this peice of code....


class Foo
{
public:
struct Bar
{
short varA;
Bar():varA(0) {} // <- huh?
};
};


Does anyone know what is going on there? Looks like some sort of inheriting going on but I am not sure as to why.
Thanks in advance

HalfVector
12-30-2006, 05:36 PM
Is the C++ way for variable initialization. It's the same as if you do:

struct Bar
{
short varA;

Bar()
{
varA = 0;
}
};

darktding
12-30-2006, 10:06 PM
thanks for the reply halfvector, this kind of assigment is new to me. There is no need to use semicolons at the end and its very odd.
Any ideas what the term to such defination? Its hards searching for help on google for such assigments.

Thanks

janimatic
12-30-2006, 10:35 PM
try to search for constructor initialization
http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=172&rl=1

CGTalk Moderation
12-30-2006, 10:35 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.