t*******i 发帖数: 4960 | 1 Is there any difference between List x; and List x();
无意中看到的。 |
f*******t 发帖数: 7549 | |
t*******i 发帖数: 4960 | 3 http://www.parashift.com/c++-faq/empty-parens-in-object-decl.ht
A big difference!
Suppose that List is the name of some class. Then function f() declares a
local List object called x:
void f()
{
List x; // Local object named x (of class List)
...
}
But function g() declares a function called x() that returns a List:
void g()
{
List x(); // Function named x (that returns a List)
...
}
【在 f*******t 的大作中提到】 : no
|
p*****p 发帖数: 379 | 4 C++的话
无参数的构造函数调用是不带括号的
但是如果List构造函数有参数就得用括号
【在 t*******i 的大作中提到】 : http://www.parashift.com/c++-faq/empty-parens-in-object-decl.ht : A big difference! : Suppose that List is the name of some class. Then function f() declares a : local List object called x: : void f() : { : List x; // Local object named x (of class List) : ... : } : But function g() declares a function called x() that returns a List:
|
t*******i 发帖数: 4960 | 5 我觉得题目指的是任意 class
Suppose that List is the name of some class.
【在 p*****p 的大作中提到】 : C++的话 : 无参数的构造函数调用是不带括号的 : 但是如果List构造函数有参数就得用括号
|
p*****p 发帖数: 379 | 6 so what?
【在 t*******i 的大作中提到】 : 我觉得题目指的是任意 class : Suppose that List is the name of some class.
|
d*****n 发帖数: 23 | 7 C++ doesn't support nested functions, right?
【在 t*******i 的大作中提到】 : http://www.parashift.com/c++-faq/empty-parens-in-object-decl.ht : A big difference! : Suppose that List is the name of some class. Then function f() declares a : local List object called x: : void f() : { : List x; // Local object named x (of class List) : ... : } : But function g() declares a function called x() that returns a List:
|