Upd: Sorry if I bother somebody with such questions. I'm 48. I'm trying to get a new profession to live from. And I need little more info than 'Do this. Don't do that. And never ask why.' :) Thanks all for answering and patience with me_kind people :)
I have Class Car.
class Car {
protected:
std::string Name;
short Year;
float Engine;
float Price;
public:
Car() {
Name = "ordinary";
Year = 1980;
Engine = 2.0;
Price = 1000.;
}
Car(std::string name, short year, float engine, float price) {
Name = name;
Year = year;
Engine = engine;
Price = price;
}
Car(Car& other) {
this->Name = other.Name;
this->Year = other.Year;
this->Engine = other.Engine;
this->Price = other.Price;
}
Car(Car&& other) {
this->Name = other.Name;
this->Year = other.Year;
this->Engine = other.Engine;
this->Price = other.Price;
}
void operator= (Car& other) {
this->Name = other.Name;
this->Year = other.Year;
this->Engine = other.Engine;
this->Price = other.Price;
}
inline std::string GetName() const { return Name; }
inline short GetYear() const { return Year; }
inline float GetEngine() const { return Engine; }
inline float GetPrice() const { return Price; }
inline void SetName(std::string n) { Name = n; }
inline void SetYear(short y) { Year = y; }
inline void SetEngine(float e) { Engine = e; }
inline void SetPrice(float p) { Price = p; }
void InitCar(std::string name, short year, float engine, float price) {
Name = name;
Year = year;
Engine = engine;
Price = price;
}
void ShowCar() {
std::cout << "Car_Name: " << Name << ";\nYear: " << Year
<< "; Engine: " << Engine << "; Price: " << Price << "\n";
}
};
Then I create vector of Car objects.
std::vector<Car> base;
Now
base.push_back(Car());
This is OK for compiler. And next OK too:
base.push_back(Car("this_car", 1900, 1.5, 1000));
But next one NOT OK:
Car car("that_car", 2001, 3.0, 3000);
base.push_back(car);
Compiler says:
no copy constructor available
When I take of Copy Constructor from Class Car, all OK.
Could anyone explain Why I should remove Copy Constructor from the Car class?
Thanks all for help and patience.