Why the following code shows error?
Why the following code shows error?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
class student
{
public:
int id;
double gpa;
student(int x, double y)
{
id=x;
gpa=y;
}
void display()
{
cout<<id<<" "<<gpa<<endl;
}
void setValue(int x, double y)
{
id=x;
gpa=y;
}
};
int main()
{
student alim, suparna, promod, nisha(115, 3.60);
alim.id=101;
alim.gpa=3.44;
cout<<alim.id<<" "<<alim.gpa<<endl;
suparna.id=105;
suparna.gpa=3.95;
suparna.display();
promod.setValue(110, 3.85);
promod.display();
nisha.display();
return 0;
}
|
Because you have defined a constructor that takes arguments, there is now no default constructor - as needed for alim et al.
You need to define a default constructor (a constructor that takes no arguments).
Thanks!
Topic archived. No new replies allowed.