destructor

Why is this class destructor declared wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 class RestaurantCheck
{
	// Public Interface
public:
	// Class Constructor(s)
	float RO(float taxrate, float tip);

	// Class Destructor
	~RO(void);

	// Client Methods

	// Private Class Members
private:
	// 1. Constant Value Declarations

	// 2. Variable Declarations
};
The destructor can't have a different name from the class.

1
2
3
4
5
class RestaurantCheck
{
public:
   ~RestaurantCheck();
};
Thanks. How about default constructor? does it have to be same name too?
Yup. All constructors and destructors must have the same name as the class.

1
2
3
4
5
6
7
8
9
class MyClass
{
private:
   int x;
public:
   MyClass(): x(0) {}      // Default c'tor
   MyClass(int x): x(x) {} // C'tor with arg
   ~MyClass(){}            // D'tor
};
Last edited on
Topic archived. No new replies allowed.