我在尝试编译项目时遇到此错误, 但我不知道为什么。 另外我得到了
“错误:'CrewMember'尚未声明” 对于类方法,以及'<'token“
之前的错误”expected','或'...'
我很确定问题是关于放置正确的“包含”但不能把我的手指放在它上面
这是我的代码:
#ifndef SMALLTOBIGIDSORTER_H_
#define SMALLTOBIGIDSORTER_H_
#include "CrewSorter.h"
#include "CrewMember.h"
//this is the line where i get the error
class SmallToBigIdSorter: public CrewSorter {
public:
SmallToBigIdSorter();
~SmallToBigIdSorter();
//this is where i'm getting the second error error: ‘CrewMember’ has not been declared
bool compare(CrewMember* member1, CrewMember* member2);
};
#endif /* SMALLTOBIGIDSORTER_H_ */
CrewSorter类:
#ifndef CREWSORTER_H_
#define CREWSORTER_H_
#include "CrewMember.h"
#include <vector>
using namespace std;
class CrewSorter {
public:
CrewSorter();
virtual ~CrewSorter();
//expected ‘,’ or ‘...’ before ‘<’ token
void addCrewMember(vector<CrewMember*>* membersList, CrewMember* newMember);
void removeCrewMember(vector<CrewMember*>* membersList, int id);
void sortCrewList(vector<CrewMember*>* membersList);
virtual bool compare(CrewMember* member1, CrewMember* member2);
};
#endif /* CREWSORTER_H_ */
CrewMember课程:
#ifndef CREWMEMBER_H_
#define CREWMEMBER_H_
#include "Movie.h"
#include <iostream>
#include <string>
using namespace std;
class Movie;
class CrewMember {
protected:
string name;
int id;
int age;
char gender;
int moviesNumber;
vector<Movie*>* movies;
string jobDescription;
public:
/*
* the function will print a string representing the
* employee unique string
*/
virtual void print(std::ostream& str) const = 0;
friend ostream& operator<<(ostream& os, const CrewMember& crewMember);
/*
* the function will add the given movie
* to the crew member
*/
void addMovie(Movie* newMovie);
/*
* the function will remove the given movie
* from the crew member
*/
void removeMovie(string movieId);
vector<Movie*> copyMovieList();
bool movieExists(Movie* movie);
/*
* will print the movie list of the crew member
*/
void printMovies();
void printMember();
/*
* constructor
*/
CrewMember();
CrewMember(string name, int id ,int age, char gender,
vector<Movie*>* movies, string jobDescription);
void removeFromAllMovies();
/*
* destructor
*/
virtual ~CrewMember();
/*
* getters
*/
vector<Movie*>* getMovies() const;
int getMoviesNumber() const;
int getId() const;
int getAge() const;
string getName() const;
string getDescription() const;
};
#endif /* CREWMEMBER_H_ */
答案 0 :(得分:0)
在你的CrewSorter和SmallToBigIdSorter中,你只使用CrewMember*
- 所以你可以在头文件(两个分类器类)中只使用前向声明。
class CrewMember;
class SmallToBigIdSorter : public CrewSorter {
// ...
然后在.cpp文件中#include "CrewMember.h"
,因此它知道实际的实现。