所以我正在做一个 uni 项目,当我尝试编译时弹出一个奇怪的错误。我已经读过它可能来自循环依赖项,但我已经检查过,这不是问题,这是头代码:
#ifndef __ScheduleHeader_H_INCLUDED__
#define __ScheduleHeader_H_INCLUDED__
#include "TrainStationHeader.h"
class Schedule
{
friend class ScheduleIterator;
public:
//get data functions
std::string getFromCity() { return fromCity; }
std::string getToCity() { return toCity; }
std::string getTrainID() { return trainID; }
std::string getDate();
std::string getTime();
std::string getTimeForTickets();
std::string getPrice() { return price; }
//set data functions + validation on the input data
bool setFromCity();
bool setToCity();
void setDate();
void setTime();
bool setTrainID();
void setPrice();
std::string createScheduleLine();
private:
int validateDate(struct tm,struct tm);
int validateTime(struct tm,struct tm);
std::string scheduleFileName;
std::string fromCity;
std::string toCity;
struct tm dateAndTime;
std::string trainID;
std::string price;
};
#endif
我添加了朋友,因为我在另一个类中有一个 Schedule 对象作为私有。我编译时的错误是:
c:\program files (x86)\windows kits\8.0\include\um\schedule.h(60): error C2146: syntax error : missing ';' before identifier 'Type'
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(60): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(61): error C2146: syntax error : missing ';' before identifier 'Offset'
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(61): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(68): error C2146: syntax error : missing ';' before identifier 'Size'
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(68): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(69): error C2146: syntax error : missing ';' before identifier 'Bandwidth'
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(69): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(70): error C2146: syntax error : missing ';' before identifier 'NumberOfSchedules'
1>c:\program files (x86)\windows kits\8.0\include\um\schedule.h(70): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
PS:我正在使用 MC VS 2012
这是 TrainStation.h ,它只是我在大多数类中使用的一堆函数和库(我知道这不是最佳实践):
#ifndef __TrainStation_H_INCLUDED__
#define __TrainStation_H_INCLUDED__
#include <iostream>
#include <string>
#include <fstream>
#include <locale>
#include <iomanip>
#include <ctime>
#include <cstdio>
#include <vector>
std::string removeWhiteSpace(std::string a);
//Resieves the file on wich to operate upon and what to search for.
//If it finds it it returns the line on wich it has been found ,if not returns -1
int checkContent(std::string FileName, std::string target);
//Give the Function the File Name with wich you would like to work and the target that you would like to delete
//It works by copying everything exept the target string to another file then renames it and deletes the old file
int deleteContent(std::string File,std::string target);
void renameFile(std::string , std::string);
bool checkFileState(std::ifstream &file);
#endif