-7

Consider the following class definition

class Pumpkin {
public:
Pumpkin(const Pumpkin & other);
~Pumpkin();
     // more public member functions
private:
double radius;
// more private member variables
};

Which of the following functions must also be implemented for the Pumpkin class for it to function correctly? (a) no parameter constructor (b) operator= (c) operator() (d) setRadius (e) operator delete

  • 5
    You just took your homework question and asked it to us, didn't you? – user2357112 Feb 25 '14 at 02:54
  • @user3342529 Are you trying to go through your [exam questions](http://stackoverflow.com/questions/22003334/is-the-result-7) with us?!? Stop this, or you'll get question banned quicker than you can correct this ... – πάντα ῥεῖ Feb 25 '14 at 03:02
  • _no parameter constructor_ - is a really bad way to describe it. A _default constructor_ (which is what it's alluding to) is defined as a constructor that can be called with no arguments. Example: `Pumpkin(int = 0)` – Captain Obvlious Feb 25 '14 at 03:03

1 Answers1

1

Which of the following functions must also be implemented for the Pumpkin class for it to function correctly?

Well, of course the ones you declared in the class body. From what you have shown you'll definitely need to define both:

Pumpkin(const Pumpkin & other);
~Pumpkin();

and I don't see any particular reason to follow the Rule of Three, since you have only shown us an harmless double.

But, if you do any RAII or your copy constructor and/or destructor are non-trivial, that's probably the case. In which case you'll have to also define:

Pumpkin& operator=(const Pumpkin&);

and if you are using C++11, it's probably a good idea to define also:

Pumpkin(Pumpkin&&);
Pumpkin& operator=(Pumpkin&&);

namely called move-constructor and move-assignment respectively.

Community
  • 1
  • 1
Shoe
  • 74,840
  • 36
  • 166
  • 272