#include <stdio.h>
class myclass
{
public:
myclass() { printf("a"); }
myclass(myclass& r) { printf("b"); }
void operator = (myclass& r){ printf("c"); }
};
int main()
{
myclass a;
myclass b(a);
myclass m = a;
return 0;
}
I was solving the problem, but I don't know well, so I'm posting a question If you run this code, it will be printed in Abb order.
Please give me a detailed explanation of the process and when the above codes are called.
c++ class
When you first do myclass a
as you see it, the default generator myclass()
is called and a is output.
The myclass b(a)
then calls the myclass(myclass&r)
constructor that receives the myclass object as a reference parameter and outputs b.
Finally, if you do myclass m=a
, you seem to have mistakenly called the copy substitution operator, but because it is the time of generation, you call the second constructor, and b is output.
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
547 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
548 PHP ssh2_scp_send fails to send files as intended
532 Uncaught (inpromise) Error on Electron: An object could not be cloned
702 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.