简体   繁体   中英

What is going on in this piece of c++ code? (Resolution operator with inheritance ?!?)

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;
}
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

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 (ie the code within the curly braces).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM