Copy Constructor

I was wondering how a copy constructor would look like if I had private member variables of vector<Class>.
So like a Class items which has private member variables of string and ints.
Then have another Class inventory which has a private member variable vector<items> in it. I want to know how to make a copy constructor like this.

So far I have something like this:
1
2
3
4
5
6
7
8
9
class Inventory{
private:
	vector<Items> _inventory;
public:
        Inventory(const Inventory& other);
};

Inventory::Inventory(const Inventory& other) : _inventory(other._inventory) {}

There is no need to define a copy constructor in this case; the compiler-generated one is fine.

See the rule of zero: https://en.cppreference.com/w/cpp/language/rule_of_three
Topic archived. No new replies allowed.