I'm not quite sure what the difference between passing *d and d2 to the constructor is:
#include <iostream>
using namespace std;
class Data
{
public:
int number;
};
class Node {
public:
Data data;
Node() {};
Node(Data d) : data(d) {};
};
int main()
{
Data* d = new Data();
Node* n = new Node(*d);
Data d2;
Node* n2 = new Node(d2);
return 0;
}
I can pass *d and d2, but in both scenarios, the data member "data" in the class "Node" is still an object by itself, is that correct? Or is there even a difference between passing an object and a dynamic object?
Dataobjects here:datamember in the class,dconstructor parameter, and eitherdord2. The former two don't care about the third.printfif you want to check this.)mainfunction they are named:*d,d2,n->data, andn2->data. There are also 2 temporary data objects that are created when you call the Node constructorNode(Data d), since calling that involves creating aDataobject on the stack nameddand you call the constructor twice. So there are 6 Data objects in sight and several copy (or move) operations are performed to pass data between them.