#include<iostream>
using namespace std;
class Stu
{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore();
void Output();
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore();
stu.Output();
}
#include"1.h"
void Avescore()
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Output()
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
错误:
Compiling...
3.cpp
G:\lianxi\my3\3.cpp(4) : error C2065: 'stu' : undeclared identifier
G:\lianxi\my3\3.cpp(4) : error C2228: left of '.ave' must have class/struct/union type
G:\lianxi\my3\3.cpp(4) : error C2228: left of '.sco1' must have class/struct/union type
G:\lianxi\my3\3.cpp(4) : error C2228: left of '.sco2' must have class/struct/union type
G:\lianxi\my3\3.cpp(8) : error C2228: left of '.id' must have class/struct/union type
G:\lianxi\my3\3.cpp(8) : error C2228: left of '.name' must have class/struct/union type
G:\lianxi\my3\3.cpp(8) : error C2228: left of '.sco1' must have class/struct/union type
G:\lianxi\my3\3.cpp(8) : error C2228: left of '.sco2' must have class/struct/union type
G:\lianxi\my3\3.cpp(8) : error C2228: left of '.ave' must have class/struct/union type
Ö´ÐÐ cl.exe ʱ³ö´í.
本人菜鸟一个,望各位指点迷津……
4 个解决方案
#1
1.在头文件中没有包含#include <string> 头文件;
2.void Avescore();void Output();这两个成员函数在外部定义时没有类名作用域,应改为:
void Stu::Avescore()
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output()
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
2.void Avescore();void Output();这两个成员函数在外部定义时没有类名作用域,应改为:
void Stu::Avescore()
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output()
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
#2
错误很多的。。
stu.ave=(stu.sco1+stu.sco2)/2.0; 这stu都没定义怎么找到。。
头文件:
#include<iostream>
using namespace std;
class Stu
{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore(Stu &stu);
void Output(Stu &stu);
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore(stu);
stu.Output(stu);
}
#include <iostream>
#include <string>
using namespace std;
void Stu::Avescore(Stu &stu)
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output(Stu &stu)
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
stu.ave=(stu.sco1+stu.sco2)/2.0; 这stu都没定义怎么找到。。
头文件:
#include<iostream>
using namespace std;
class Stu
{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore(Stu &stu);
void Output(Stu &stu);
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore(stu);
stu.Output(stu);
}
#include <iostream>
#include <string>
using namespace std;
void Stu::Avescore(Stu &stu)
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output(Stu &stu)
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
#3
谢谢各位,在知道怎么弄了
#4
头文件:
#include<iostream>
using namespace std;
class Stu{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore();
void Output();
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore();
stu.Output();
}
#include"1.h"
void Stu::Avescore()
{
ave=(sco1+sco2)/2.0;
}
void Stu::Output()
{
cout<<id<<" "<<name<<" "<<sco1<<" "<<sco2<<" "<<ave<<" "<<endl;
}
#include<iostream>
using namespace std;
class Stu{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore();
void Output();
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore();
stu.Output();
}
#include"1.h"
void Stu::Avescore()
{
ave=(sco1+sco2)/2.0;
}
void Stu::Output()
{
cout<<id<<" "<<name<<" "<<sco1<<" "<<sco2<<" "<<ave<<" "<<endl;
}
#1
1.在头文件中没有包含#include <string> 头文件;
2.void Avescore();void Output();这两个成员函数在外部定义时没有类名作用域,应改为:
void Stu::Avescore()
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output()
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
2.void Avescore();void Output();这两个成员函数在外部定义时没有类名作用域,应改为:
void Stu::Avescore()
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output()
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
#2
错误很多的。。
stu.ave=(stu.sco1+stu.sco2)/2.0; 这stu都没定义怎么找到。。
头文件:
#include<iostream>
using namespace std;
class Stu
{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore(Stu &stu);
void Output(Stu &stu);
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore(stu);
stu.Output(stu);
}
#include <iostream>
#include <string>
using namespace std;
void Stu::Avescore(Stu &stu)
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output(Stu &stu)
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
stu.ave=(stu.sco1+stu.sco2)/2.0; 这stu都没定义怎么找到。。
头文件:
#include<iostream>
using namespace std;
class Stu
{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore(Stu &stu);
void Output(Stu &stu);
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore(stu);
stu.Output(stu);
}
#include <iostream>
#include <string>
using namespace std;
void Stu::Avescore(Stu &stu)
{
stu.ave=(stu.sco1+stu.sco2)/2.0;
}
void Stu::Output(Stu &stu)
{
cout<<stu.id<<" "<<stu.name<<" "<<stu.sco1<<" "<<stu.sco2<<" "<<stu.ave<<" "<<endl;
}
#3
谢谢各位,在知道怎么弄了
#4
头文件:
#include<iostream>
using namespace std;
class Stu{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore();
void Output();
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore();
stu.Output();
}
#include"1.h"
void Stu::Avescore()
{
ave=(sco1+sco2)/2.0;
}
void Stu::Output()
{
cout<<id<<" "<<name<<" "<<sco1<<" "<<sco2<<" "<<ave<<" "<<endl;
}
#include<iostream>
using namespace std;
class Stu{
public:
string id;
string name;
float sco1;
float sco2;
float ave;
public:
void Avescore();
void Output();
};
源文件:
#include"1.h"
#include<iostream>
#include<string>
using namespace std;
void main()
{
Stu stu;
stu.id="1001";
stu.name="gis";
stu.sco1=98;
stu.sco2=90;
stu.Avescore();
stu.Output();
}
#include"1.h"
void Stu::Avescore()
{
ave=(sco1+sco2)/2.0;
}
void Stu::Output()
{
cout<<id<<" "<<name<<" "<<sco1<<" "<<sco2<<" "<<ave<<" "<<endl;
}