class Points {
private:
int* x {};
int* y {};
public:
Points(size_t size) : x(newint[size]), y(newint[size]) {}
// These need to be provided if required as the default ones are not appropriate here
Points(const Points&) = delete;
Points& operator=(const Points&) = delete;
~Points() {
delete[] x;
delete[] y;
}
};
class Triangle {
public:
Points p;
Triangle() : p(3) {}
};
1) Yes. p will be default initialised to Points(3). If p isn't initialised elsewhere in a constructor then this will be it's value.
2) = delete means that the specified function isn't available and that any use will cause a compiler error. For classes, the compiler generates default functions for copy/move constructor and copy/move operator= in some cases. Where these are generated they do a shallow copy (just copy the contents of the member variables). When dynamic memory is used, a deep copy (allocation of new memory and copying of the contents from old to new) is required. Using the default constructors will cause problems - as in this case. That's why I specified these to be =delete so that if they are used you'll get a compiler error until correct implementations are provided.