Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 为什么';t构造函数调用?_C++_Constructor - Fatal编程技术网

C++ 为什么';t构造函数调用?

C++ 为什么';t构造函数调用?,c++,constructor,C++,Constructor,我试图检查move构造函数调用的行为: #include <iostream> struct A { A(){ std::cout << "A()" << std::endl; }; A(A&){ std::cout << "A(A&)" << std::endl; }; A(A&&){ std::cout << "A

我试图检查move构造函数调用的行为:

#include <iostream>

struct A
{
    A(){ std::cout << "A()" << std::endl; };
    A(A&){ std::cout << "A(A&)" << std::endl; };
    A(A&&){ std::cout << "A(A&&)" << std::endl; };
};

A foo(){
    return A();
}

A t(A()); //produce no output, but because of A() is prvalue, I expected A(A&&) was produced
A d(foo()); //OK, produces A()\n A(A&&)\n A(A&&)

int main(){ }
#包括
结构A
{
A(){std::cout

是另一个函数的抽象声明

是一个函数声明,其返回类型为
a
,一个参数类型为
a()
,其中
a()
依次为函数类型id

举个例子

#include <iostream>

int t( int() );
int t( int ( x ) ) { return x; }

int main() 
{
    std::cout << t( 10 ) << std::endl;
}   
char ( ( [10] ) )
那么这个

void f( char ( ( [10] ) ) );
是有效的函数声明


如果不使用参数标识符,可以忽略它们。

t
不是一个变量。这对我来说不是问题。为什么对声明进行如此解析?@DmitryFucintv,查找最麻烦的解析。您可以通过使用
{}
而不是
()
来创建临时(以及其他对象)来轻松解决它.你说它是一个函数。那我为什么不能调用它呢?.啊,因为一个函数声明一个指针类型的参数指向函数,返回一个,而不仅仅是一个..我已经用uderstood.这不应该说
a t(a());
是一个接受一个参数的函数声明,而该参数本身是一个不接受参数并返回类型
a
的函数?
void f( char ( ( [10] ) ) );