This is not a duplicate. The most unpleasant parsing: why A a (()); work? , which is based on parsing in a form A a(());, the thinking of which will be able to construct an object by default Ausing an additional set of parentheses.
On the contrary, my question concerns two classes: fand g, where fhas a default constructor, and gctor accepts f. I want to call gctor with a temporary argument f, without using a single initialization syntax. There std::coutin gctor, so the lack of output means declaring a function instead of an gobject. I commented on the sample code with 3 numbers in the comments. # 1 and # 2 were compiled C # 3 commented out, and vice versa:
#include <iostream>
struct f {};
struct g {
g(f) { std::cout << "g ctor\n"; }
};
int main() {
g( f() );
g( ( f() ) );
}
# 1: I thought that # 1 declares an anonymous function that returns gand takes a pointer to a function that takes 0 arguments and returns f. I'm wrong?
# 2: , , # 2 , f ctor. . ?
# 3: - # 2, # 3 myG. # 3 , # 1 # 2 . VC12:
error LNK2019: unresolved external symbol "struct g __cdecl f(void)" (?f@@YA?AUg@@XZ) referenced in function _main
fatal error LNK1120: 1 unresolved externals.
g++ 4.8: undefined reference to 'f()'
?
# 3 ?
?