编译错误,无法解决
#include <math.h>
#include <iostream>
#include <fstream>
#include <string>
class ReadGPSo
{
public:
int year,month,day,hour,minute;
double second;
void ReadFileo();
}
#include "ReadGPSo.h "
using namespace std;
void ReadGPSo::ReadFileo()
{
string str,Endheader,strhead;
Endheader= " END OF HEADER ";
//openfile and check the dada header
ifstream gpsfileo;
gpsfileo.open( "E:\\VC编程\\data\\05731600.06o ");
if(!gpsfileo)
cout < < "The 'o 'file you want to open is not exist! " < <endl;
do
{
getline(gpsfileo,str);
}while(!(str==Endheader));
// get time
int detect;
getline(gpsfileo,strhead);
year=atoi(strhead.substr(0,4).data());
month=atoi(strhead.substr(4,3).data());
day=atoi(strhead.substr(7,3).data());
hour=atoi(strhead.substr(10,3).data());
minute=atoi(strhead.substr(13,3).data());
second=atof(strhead.substr(16,10).data());
detect=atoi(strhead.substr(26,3).data());
if(!detect)
cout < < "This data is invalidation! " < <endl;
cout < < "aaaaaaaaa " < <endl;
gpsfileo.close();
}
#include "ReadGPSo.h "
int main()
{
ReadGPSo gpso;
gpso.ReadFileo();
return 1;
}
Compiling...
main.cpp
E:\VC编程\GPSposition1\main.cpp(10) : error C2628: 'ReadGPSo ' followed by 'int ' is illegal (did you forget a '; '?)
E:\VC编程\GPSposition1\main.cpp(20) : error C2440: 'return ' : cannot convert from 'const int ' to 'class ReadGPSo '
No constructor could take the source type, or constructor overload resolution was ambiguous
E:\VC编程\GPSposition1\main.cpp(21) : warning C4508: 'main ' : function should return a value; 'void ' return type assumed
ReadGPSo.cpp
E:\VC编程\GPSposition1\ReadGPSo.cpp(3) : error C2143: syntax error : missing '; ' before 'using '
Error executing cl.exe.
同样类似的一个另一个类调用却可行,不知道怎么回事
[解决办法]
class ReadGPSo
{
public:
int year,month,day,hour,minute;
double second;
void ReadFileo();
};
少了分号
------解决方案--------------------
又出现问题了,我用这种动态分配空间的方法的话,这些动态分配的参数被释放后就不能使用了,而我是要在主程序里调用的,该如何实现阿?
只有把这些在函数里分配的内存的指针返回到主函数,在主函数接收之后,一个一个的调用
delete []
想返回多个参数,可以用引用传参.
例如
void re(int *&p1,int *p&2)
{
p1=new int[3];
p2=new int[4];
}
void main()
{
int *p,*q;
re(p,q); //这样就用p,q分别申请了一块内存,并成功带回来了.你的四个指针也一样道理
}
