When I did 'delete myCar' and 'delete myTruck' on their own, it said it wasn't declared in that method.
Valgrind still tells me there are memory leaks in the executive::executive() method where I make the class objects.
What's a better way to resolve this issue?
In the case of raw pointers the copy assignment operator and copy constructor should be deleted as an object of type Executive has two data members, myCar, myTruck, that manage, in turn, a Car and a Truck object respectively created on the heap. With copy construction or assignment if myCar and myTruck are assigned to the corresponding data-members of the newly created object then we have two pointers to the same Car and Truck object and if delete is called on either of the pointers then the other pointer is left dangling.
An alternative would be to create a new Car and a new Truck object with same m_speed values as the right-hand side object and assign the pointer data-members of the new Executive object to these but that would just be replicating the ctor.
In the case of std::unique_ptr, the copy ctor and copy assignment operators for Executive would be deleted automatically as it has std::unique_ptr data-members. The Executive move ctor will, in turn, use move assignment as the data-members are unique_ptr's while the move assignment operator remains unchanged: