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

Viewed 64939

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();
}
3 Answers

Similar code:


Change from:

class Solution {
public:
  static int Solution::curr_h; // ----------------- ISSUE: "Solution::" is extra
  static int Solution::curr_m; // ----------------- ISSUE: "Solution::" is extra
};

int Solution::curr_h = 0;
int Solution::curr_m = 0;

to:

class Solution {
public:
  static int curr_h;  // ----------------- FIX: remove "Solution::"
  static int curr_m;  // ----------------- FIX: remove "Solution::"
};

int Solution::curr_h = 0; // <------ good here - "Solution::" is required
int Solution::curr_m = 0; // <------ good here - "Solution::" is required

  • This happens because copy pasting statics require initialization outside of class, but also requires all the declaration (int) too.
  • Though it is correct, wish there is a easier/ better way to do the same.
Related