c – 错误“额外资格”学生::’成员’学生'[-fpermissive]“
发布时间:2020-12-16 07:51:07 所属栏目:百科 来源:网络整理
导读:我在成员’学生'[-fpermissive]上获得了更多的资格“student ::”的错误. 还有为什么name :: name这样的语法在构造函数中使用? #includeiostream#includestring.husing namespace std;class student{ private: int id; char name[30]; public:/* void read(
我在成员’学生'[-fpermissive]上获得了更多的资格“student ::”的错误.
还有为什么name :: name这样的语法在构造函数中使用? #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(); } 解决方法
成员函数/构造函数/析构函数的类定义不需要诸如student ::的资格.
所以这段代码, student::student() { id=0; strcpy(name,"undefine"); } 应该是这样的: student() { id=0; strcpy(name,"undefine"); } 资格学生::仅当您在课外定义成员函数(通常在.cpp文件中)时才需要. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |