2
Ich habe diesen Code:Warum wird dieser Konstruktor zweimal aufgerufen?
// 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;
}
Der resultierende Druck ist:
Hello world!
Hello world!
Warum dies geschieht?
Das hat nichts mit Bewegung Semantik zu tun; Es gibt keine Bewegungen in Ihrem Code. –