Search
 
SCRIPT & CODE EXAMPLE
 

CPP

prevent copy c++

Method 1: Private copy constructor and copy assignment operator
  class Car {
public:
  Car(): owner() {}
  void setOwner(Person *o) { owner = o; }
  Person *getOwner() const { return owner; }
  void info() const;
private:
  Car(const Car&);
  Car& operator=(const Car&);
  Person *owner;
};

Method 2: Deleted copy constructor and copy assignment operator
  class Car {
public:
  Car(const Car&) = delete;
  void operator=(const Car&) = delete;
  Car(): owner() {}
  void setOwner(Person *o) { owner = o; }
  Person *getOwner() const { return owner; }
private:
  Person *owner;
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: sum of first 100 natural numbers 
Cpp :: oncomponentendoverlap ue4 c++ 
Cpp :: QVariant to int 
Cpp :: 1768. Merge Strings Alternately leetcode solution in c++ 
Cpp :: heredar constructor c++ 
Cpp :: array copx c++ 
Cpp :: c++ delay 
Cpp :: c++ unittest in ros 
Cpp :: adding variables c++ 
Cpp :: rethrow exception c++ 
Cpp :: Operators in C / C++ 
Cpp :: volumeof a sphere 
Cpp :: c++ program to convert fahrenheit to celsius 
Cpp :: Abstract factory C++ code 
Cpp :: cyclically rotate an array by once 
Cpp :: Arduino Real TIme Clock 
Cpp :: string append at position c++ 
Cpp :: qt file explorer 
Cpp :: c++ string concatenation 
Cpp :: How to generate all the possible subsets of a set ? 
Cpp :: A Program to check if strings are rotations of each other or not 
Cpp :: c++ get index of map element 
Cpp :: c++ string example 
Cpp :: print all number between a and b in c++ 
Cpp :: C++ file . 
Cpp :: how to do if command in c++ 
Cpp :: return multiple values c++ 
Cpp :: c++ throe 
Cpp :: how to print double value up to 9 decimal places in c++ 
Cpp :: c ++ Prefix Sum of Matrix (Or 2D Array) 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =