0

I don't know what is going on in this piece of code. this is from a working piece of code that I have to understand.

orange::orange():
  hello_short(false),
  hello_long(false),
  foo(NULL),
  foo2(NULL),
  quiet(false)
{
  res  = NULL;
  good = true;
}
bames53
  • 86,085
  • 15
  • 179
  • 244
nulltorpedo
  • 1,195
  • 2
  • 12
  • 21
  • For the weird colon after the constructor's name, see [this FAQ entry](http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor). – sbi Jan 18 '12 at 19:03

2 Answers2

5
orange::orange():

simplies says that you are defining a function of the class orange (the left part), the function is called "orange" (the right part) and takes no arguments. Since the function is named the same as the class and returns no value, it's aconstructor of your class

The rest is an initialisation list : http://www.cprogramming.com/tutorial/initialization-lists-c++.html

lezebulon
  • 7,607
  • 11
  • 42
  • 73
1

It initializes the class members with the given values (hello_short will be false, hello_long will be false, foo will be NULL, etc), sets res to NULL and sets good to true.

The initialization list is always done before executing the constructor (i.e. the code within the curly braces).

Also, there is a syntax error: after foo2(NULL), a comma should come.