2
이 코드를 가지고 :이 생성자가 두 번 호출되는 이유는 무엇입니까?
// Example program
#include <iostream>
#include <string>
class Hello{
public:
Hello(){std::cout<<"Hello world!"<<std::endl;}
};
class Base{
public:
Base(const Hello &hello){ this->hello = hello;}
private:
Hello hello;
};
class Derived : public Base{
public:
Derived(const Hello &hello) : Base(hello) {}
};
int main()
{
Hello hello;
Derived d(hello);
return 0;
}
결과 인쇄는 다음과 같습니다 이런 이유
Hello world!
Hello world!
?
이 이동 시맨틱 할 수 없다; 당신의 코드에는 움직임이 없습니다. –