Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 882 Bytes

methods_for_classes.md

File metadata and controls

49 lines (36 loc) · 882 Bytes
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 ---

Methods for Classes

string

string s ("Hallo Welt");
class Car{
public:
    string name;
    int age;
    Car(string name, int age) : name(name), age(age) {

    }
};

copyconstructor

  • 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;
}

See also