C奇怪的编译错误:错误:从“对象”类改变“对象”的含义
发布时间:2020-12-14 20:04:12 所属栏目:百科 来源:网络整理
导读:我甚至不知道该去哪里.谷歌不是很有帮助.和我之前的问题一样.我正在使用TextMate的Command R来编译项目. game.h:16:error: declaration of ‘Player* HalfSet::Player() const’ players.h:11:error: changes meaning of ‘Player’ from ‘class Player’ g
我甚至不知道该去哪里.谷歌不是很有帮助.和我之前的问题一样.我正在使用TextMate的Command R来编译项目.
player.h文件(部分) #ifndef PLAYERS_H #define PLAYERS_H using namespace std; #include <string> #include <vector> #include <istream> #include <iomanip> #include "generics.h" class Player{ //Line 11 public: //getters long Id() const; string FirstName() const; string LastName() const; string Country() const; //setters void setId(long id); void setFirstName(string s); void setLastName(string s); void setCountry(string s); //serializing functions void display(ostream &out); void read(istream &in); void write(ostream &out); //Initalizers Player(); Player(istream &in); Player(string firstName,string lastName); Player(string firstName,string lastName,string country); Player(long id,string firstName,string country); ~Player(); private: long _id; string _firstName; string _lastName; string _country; }; game.h文件(部分) #ifndef GAME_H #define GAME_H #include "generics.h" #include "players.h" #include <string> #include <vector> #include <istream> #include <iomanip> using namespace std; class HalfSet{ public: //getters Player* Player() const; //Line 16 int GamesWon() const; int TotalPoints() const; int Errors() const; //setters void setPlayer(Player* p); void setGamesWon(int games); void setTotalPoints(int points); void setErrors(int errors); //Serialization void display(ostream &out) const; void read(istream &in) const; void write(ostream &out) const; //Initalizers HalfSet(); ~HalfSet(); private: Player* _player; int _gamesWon; int _points; int _errors; }; 这里发生了什么? 解决方法
在C中,您不能将函数命名为类/ struct / typedef.你有一个名为“Player”的类,所以HalfSet类有一个名为“Player”(“Player * Player()”)的函数.您需要重命名其中一个(可能将HalfSet的Player()更改为getPlayer()或其他).
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |