<分区>
假设我有一个结构:
struct structazauras
{
string bla;
}
还有一些函数(在我的例子中,这个函数实际上是某个类的构造函数,但我认为这不是问题所在):
void myfunc(structazauras& mystruct) { }
然后我调用 myfunc 的地方:
..
myfunc(structazauras());
..
我得到一个错误:
no matching function for call to myfunc(structazauras) candidates are myfunc(structazauras&)
如果我将代码更改为:
structazauras tmp;
myfunc(tmp);
它会很好地工作。
我觉得如果 structazauras
他(编译器)传递对匿名实例的引用有问题,但为什么呢?匿名实例存在于调用函数的堆栈中。