Declaring an uninitialized variable without a null constructor

Consider the DUPoint class, the declaration of which is given below. Suppose this code appears in a file called DUPoint.h:

 #include <string> class DUPoint { public: DUPoint (int x, int y); int getX () const; int getY () const; void setX (int x); void setY (int y); void print(); private: int x_; int y_; }; 

Is it true that you cannot declare an uninitialized DUPoint variable with an expression, such as DUPoint P; using this class as the current configuration since it does not have a zero constructor?

+4
source share
2 answers

Yes, if there is a constructor declared by the user, the default constructor will not be generated implicitly by the compiler.

+6
source

If you provide a constructor, then by default it will not be generated. Of course, adding one is a question

 DUPoint(); 
+1
source

Source: https://habr.com/ru/post/1307983/


All Articles