+ 6

output explanation

could someone explain this output please https://code.sololearn.com/cDUQBqanhI2H/?ref=app

20th Oct 2019, 8:58 PM
ABADA S
ABADA S - avatar
12 odpowiedzi
+ 5
Aymane Boukrouh I know that but it should invoke a constructor that print something
20th Oct 2019, 9:27 PM
ABADA S
ABADA S - avatar
+ 5
sneeze your code has normal case an object creation invoked some constructors but in my code I expect to get A() A() B(A) but I got nothing
20th Oct 2019, 9:35 PM
ABADA S
ABADA S - avatar
+ 3
There is no output because there is simply no object that is being instantiated. It seems to be a language paradigm to evaluate whatever possible as a function. So in this case, the parser thinks you are introducing a function, where the expression B b( A() ); is a function declaration for a function called "b", which returns an object of type B, and takes a function pointer to a function returning an object of type A with no parameters as its argument. Due to this evaluation, no object is instantiated and thus no constructor is actually called.
20th Oct 2019, 9:47 PM
Shadow
Shadow - avatar
+ 3
When the legend comes 😍😍 thank you very much it never came to my mind I got it very well could you please put some information about "vexing parse" and its synonymous ? Edited: could you please adjust my code and define the function and call it
20th Oct 2019, 10:01 PM
ABADA S
ABADA S - avatar
+ 2
Have a look at my code. Please read about methods and constructors. https://code.sololearn.com/c1EbvL6jrQb4 What is the output you wanted ? https://en.cppreference.com/w/cpp/language/copy_constructor
20th Oct 2019, 9:28 PM
sneeze
sneeze - avatar
+ 2
sneeze I tried that but in my information A() creates a temporary object check this question please https://www.sololearn.com/discuss/2028897/?ref=app A() should be an object creating if we write A(); like that without passing it as an argument it will call the constructor as expected but when we pass it I don't know what's happening also B has just one constructor , if A() is a method that returns something the compiler must show as an error
20th Oct 2019, 9:44 PM
ABADA S
ABADA S - avatar
+ 1
There is no output
20th Oct 2019, 9:12 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
A constructor is not a normal method; B b; Creates a object of type B, The object is called b This automatically invokes the constructor of type B.
20th Oct 2019, 9:38 PM
sneeze
sneeze - avatar
0
your code is B b(A()); Code should be : A a; // create object of type A B b(a); //create object of type B, give object "a" as parameter This should print (A) (A) B(A)
20th Oct 2019, 9:41 PM
sneeze
sneeze - avatar
0
First off your work should be mostly done in the main function. Second you need to set up a cout code for what you want to output
21st Oct 2019, 11:29 PM
Kevin
Kevin - avatar