Construction leak ??

Hi All, Dumb C++ question, I wanted your view on

Suppose
class A
{
public:
// constructor
// copy constructor
A(const A& a)
{
this->x = a.x;
this->y = a.y;
this->z = a.z;
}

private:
double x, y, z;
}

Does this mean that if some third person has the definition of class, he can virtually copy all the elements from a given object of A into new object of A and then use it ? Does this not be a problem when I don't want someone else be able to copy it this way but just me ?
he can virtually copy all the elements from a given object of A into new object of A and then use it

Yes, this class is copyable, like the majority of C++ classes.

when I don't want someone else be able to copy it

Then you can
1) document your desire (e.g. std::FILE, better known as the C library's FILE, is copyable, but it's documented that using a copy for I/O yields undefined behavior)

2) delete the copy constructor (e.g. std::fstream, std::thread, and other movable, but not copyable classes)

but just me

You the library writer who is designing this class?
3) make the copy constructor private, so that it would only be called from those member functions you wrote.

C++ works best with copyable types, though, anything else requires significant justification.
Topic archived. No new replies allowed.