Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error "extra qualification ‘student::’ on member ‘student’ [-fpermissive] "

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();
}
like image 740
wizneel Avatar asked Jul 27 '12 17:07

wizneel


2 Answers

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.

like image 164
Nawaz Avatar answered Sep 27 '22 23:09

Nawaz


It would be correct if definition of constructor would appear outside of class definition.

like image 39
tumdum Avatar answered Sep 28 '22 00:09

tumdum