我不知道这段代码是怎么回事。这是来自我必须了解的一段代码。这段C++代码是怎么回事? (Resolution operator with inheritance?!?)
orange::orange():
hello_short(false),
hello_long(false),
foo(NULL),
foo2(NULL),
quiet(false)
{
res = NULL;
good = true;
}
我不知道这段代码是怎么回事。这是来自我必须了解的一段代码。这段C++代码是怎么回事? (Resolution operator with inheritance?!?)
orange::orange():
hello_short(false),
hello_long(false),
foo(NULL),
foo2(NULL),
quiet(false)
{
res = NULL;
good = true;
}
orange::orange():
simplies说,你所定义的类橙色(左部)的功能,该功能被称为“橙”(右部)和不带任何参数。由于该功能被命名为相同类和没有返回值,这是aconstructor类
剩下的就是一个初始化列表:http://www.cprogramming.com/tutorial/initialization-lists-c++.html
它初始化与给定值的类成员(hello_short
将false
,hello_long
将是false
,foo
将是NULL
等),将res
设置为NULL
并将good
设置为true
。
初始化列表总是在执行构造函数(即花括号内的代码)之前完成。
此外,还有一个语法错误:在foo2(NULL)
之后,应该出现逗号。
对于构造函数名称后的奇怪冒号,请参见[本FAQ文章条目](http://stackoverflow.com/questions/1711990/what-is-this-weird-colon-member-syntax-in-the-constructor )。 – sbi 2012-01-18 19:03:57