Identify the error in the following program include class Ro
Identify the error in the following program. #include class Room {int length, width; Room (int 1, int w = 0): length(1), width (w) {}}; int main() {| Room room1; Room room2(12, 8);}
Solution
#include<iostream>
class Room{
int length,width;
public:
Room(int l,int w=0) : length(l),width(w)
{
}
};
int main()
{
Room room1;
Room room2(12,8);
return 0;
}
There are 2 problems with the above code:
First one:
Room room1;
Since you define a constructor with 2 parameters you have to define the constructor with no parameters too because compiler thinks that if you have defined any constructor than you have to take care the definition of default constructor too and it wont be provided by the compiler.
Second problem:
Since return type of main function is int
last statement of the program should be return 0;
