64,636
社区成员
发帖
与我相关
我的任务
分享
Student::Student()
{}
#include <iostream>
using namespace std;
class Student
{
private:
int num; //学号
public:
Student(); //默认构造函数
Student(int n); //构造函数
void show()const;
};
Student::Student()
{ //error: constructors not allowed a return type
num = 0;
}
Student::Student(int n)
{
num = n;
}
void Student::show()const
{ //error: show:modifiers not allowed on nonmember functions
std::cout<<num;
}
int main()
{
Student s1;//error 怎么错了?
s1.show();
Student s2(1);
s2.show();
system("pause");
return 0;
}
#include <iostream>
using namespace std;
class Student
{
private:
int num; //学号
public:
Student();
Student(int n);
void show()const;
};
Student::Student()
{
num = 0;
}
Student::Student(int n)
{
num = n;
}
void Student::show()const
{
cout <<num<<endl;
}
int main()
{
Student s1;
s1.show();
Student s2(1);
s2.show();
return 0;
}
#include <iostream>
using namespace std;
class Student
{
private:
int num; //学号
public:
Student(); //默认构造函数
Student(int n); //构造函数
const void show(); //改变下这个函数的写法
}; //这里漏了一个分号
Student::Student()
{ //error: constructors not allowed a return type
num = 0;
}
Student::Student(int n)
{
num = n;
}
const void Student::show()
{ //error: show:modifiers not allowed on nonmember functions
cout <<num<<endl;
}
int main()
{
Student s1;//error 怎么错了?
s1.show();
Student s2(1);
s2.show();
return 0;
}
#include <iostream>
using namespace std;
class Student
{
private:
int num; //学号
public:
Student(); //默认构造函数
Student(int n); //构造函数
void show()const;
};//注意分号
Student::Student()
{ //error: constructors not allowed a return type
num = 0;
}
Student::Student(int n)
{
num = n;
}
void Student::show()const//注意域
{ //error: show:modifiers not allowed on nonmember functions
cout <<num;
}
int main()
{
Student s1;//error 怎么错了?
s1.show();
Student s2(1);
s2.show();
return 0;
}