c++问题 找不到出错的地方!!!
来源:百度知道 编辑:UC知道 时间:2024/05/27 06:45:00
class student
{ public:
student(int n,float s):num(n),score(s){} //等价于student(int n,float s) {num=n;score=s;}
void change(int n,float s) {num=n;score=s;}
void display(){cout<<""<<score<<endl;}
friend void fun(student &std);
private:
int num;
float score;
};
void fun(student &std)
{
std.change(int &n,float &s);
{
std.change(101,80.5);
}
std.display();
}
void main()
{student stud;
fun(student &stud);
stud.change(101,80.5);
stud.display();
}
--------------------Configuration: ccc - Win32 Debug--------------------
Compiling...
ccc.cpp
c:\documents and settings\computer\桌面\ccc.cpp(14) : error C2144: syntax error : missing ')' before type 'int'
c:\documents and settings\computer\桌面\ccc.cpp(14) : error C2660: 'change' :
#include <iostream>
using namespace std;
class student
{ public:
student(){}
student(int n,float s):num(n),score(s){} //等价于student(int n,float s) {num=n;score=s;}
void change(int n,float s) {num=n;score=s;}
void display(){cout<<""<<score<<endl;}
friend void fun(student &std);
private:
int num;
float score;
};
void fun(student &std)
{
//std.change(int n,float s);
//{
std.change(101,80.5);
//}
std.display();
}
void main()
{
student stud;
fun(stud);
stud.change(101,80.5);
stud.display();
}
注:
1、student stud;定义对象时缺少对应的构造函数。
2、引用并不是指针,而是一个变量的别名。
作为函数参数时,实参直接用变量,而不是变量的地址
--------------------Configuration: For_testing - Win32 Debug--------------------
Compiling...
For_testing_main.cpp
e:\My_Documents\my_Cpp\For_testing\For_