-2

I don't know what it is called so I'll show the code...maybe it is related to constructor overloading :

class Classname{
public:
      Classname(Class1& pClass1,Class2& pClass2);
private:
      Classname(const Classname&);
      void operator=(const Classname&);
};

What do the 2 statements in private section do ?

Rahul Naik
  • 105
  • 1
  • 9

1 Answers1

1

Putting the 'copy constructor' and 'copy assignement operator' in private is just a way to forbid their use as they will raise an error when used outside of this class.

If you really want to forbid their use, I would suggest doing it this way :

class Classname
{
public:
      Classname(Class1& pClass1,Class2& pClass2);
      Classname(const Classname&) = delete;
      void operator=(const Classname&) = delete;
private:
      ...
};
rak007
  • 973
  • 12
  • 26