I am getting an error extra qualification ‘student::’ on member ‘student’ [-fpermissive]
.
And also why name::name
such syntax is used in constructor?
#include<iostream>
#include<string.h>
using namespace std;
class student
{
private:
int id;
char name[30];
public:
/* void read()
{
cout<<"enter id"<<endl;
cin>>id;
cout<<"enter name"<<endl;
cin>>name;
}*/
void show()
{
cout<<id<<name<<endl;
}
student::student()
{
id=0;
strcpy(name,"undefine");
}
};
main()
{
student s1;
// s1.read();
cout<<"showing data of s1"<<endl;
s1.show();
// s2.read();
//cout<<"showing data of s2"<<endl;
//s2.show();
}
In-class definitions of member function(s)/constructor(s)/destructor don't require qualification such as student::
.
So this code,
student::student()
{
id=0;
strcpy(name,"undefine");
}
should be this:
student()
{
id=0;
strcpy(name,"undefine");
}
The qualification student::
is required only if you define the member functions outside the class, usually in .cpp file.
It would be correct if definition of constructor would appear outside of class definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With