tags:

views:

71

answers:

2

Consider the DUPoint class, whose declaration appears below. Assume this code appears in a file named 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 a statement such as DUPoint P; using this class as currently configured because it has no null constructor?

+6  A: 

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

Georg Fritzsche
thanks. and thanks for the explanation...i understand it now
xbonez
+1  A: 

If you provide a constructor, then the default one won't be generated. Of course, adding one is just a matter of

DUPoint();
Maulrus