constant variables and functions in the same program cpp
#include<bits/stdc++.h>
using namespace std;
class student
{
public:
const int roll;
const string name;
student (int r,string n)
:roll(r),name(n)
{
cout<<roll<<endl;
cout<<name<<endl;
}
void display()
{
cout<<"Disp\n";
}
};
int main()
{
student obj(2003081,"ismail");
student o; //ERROR
o.display();
return 0;
}
I can't understand, why the compiler shows "no matching function for call to 'student::student()' "? Where is the problem and how can I overcome this?