| description | Learn how to Handle with more Methods for Classes |
|---|---|
| title | Methods for Classes Handling |
| ms.date | 19/11/2023 |
| ms.topic | conceptual |
| author | fejo-git |
| ms.reviewer | --- |
string s ("Hallo Welt");
class Car{
public:
string name;
int age;
Car(string name, int age) : name(name), age(age) {
}
};
- C++ automatically generates a copy constructor.
- When explicitly defining the constructor, modifications can be made.
- Set the copy constructor to private to ensure that variables must be passed by reference.
Car(Car &other) {
this->name = other.name;
}