Trying to avoid the copy-assignment of object by mentioning as delete to assignment overloading. But still, below code is not showing error for copy assignment. Vehicle class object trying to avoid the assignment operation after creating the new class object.
class Vehicle {
private:
const int _registrationNum;
const int _yearOfRegistration;
const int _saleAmount;
std::string _currentOwnerName;
OwnersList* _listOfOwners;
public:
Vehicle(int regNum, int year, int saleAmount,std::string& name, std::string& addr)
:_registrationNum(regNum),
_yearOfRegistration(year),
_saleAmount(saleAmount),
_currentOwnerName(name) {
_listOfOwners=new OwnersList(name,addr,year);
}
Vehicle(const Vehicle&)=delete;
Vehicle(const Vehicle*)=delete;
void operator=(const Vehicle&)=delete;
Vehicle* operator=(const Vehicle*)=delete;
void printDetails() {
std::cout<<"\n Registration Number :"<<_registrationNum;
std::cout<<"\n Year Of Registration:"<<_yearOfRegistration;
std::cout<<"\n Sale Amount :"<<_saleAmount;
std::cout<<"\n Current Owner Name :"<<_currentOwnerName;
OwnersList* itr =_listOfOwners;
while(itr != nullptr) {
std::cout<<"\n Previous Owner Name: "<<itr->getOwnerName();
std::cout<<"\n Previous Sale Year : "<<itr->getSaleYear();
std::cout<<"\n Address : "<<itr->getAddressOfOwner();
itr=itr->nextOwner;
}
}
};
int main() {
cout<<"\n +++ Checking for Vehicle Registration +++ \n";
std::string name="shrikant";
std::string address="Indi";
Vehicle* newVehicleObj = new Vehicle(9876,2021,200000,name,address);
newVehicleObj->printDetails();
Vehicle* newVehicleObj1 = new Vehicle(987,2022,300000,name,address);
newVehicleObj1->printDetails();
newVehicleObj=newVehicleObj1;
newVehicleObj->printDetails();
return 0;
}
Please check and correct me.