Rook brookL();board[0][0].setPIEceObj(brookL);
我收到以下错误:
ChessBoard.cpp:16:35: error: no matching function for call to 'Space::setPIEceObj(Rook (&)())' board[0][0].setPIEceObj(brookL); ^In file included from ChessBoard.h:13:0,from ChessBoard.cpp:5:Space.h:62:10: note: candIDate: voID Space::setPIEceObj(PIEce&) voID setPIEceObj(PIEce &); ^Space.h:62:10: note: no kNown conversion for argument 1 from 'Rook()' to 'PIEce&'
这是我的代码:
ChessBoard.h:
#ifndef CHESSBOARD_H#define CHESSBOARD_H#include "Space.h"using namespace std;class ChessBoard {private: Space board[8][8]; // board[0][0] is the upper-left corner of the board and // board[7][7] is the lower-right corner of the boardpublic: ChessBoard();};#endif /* CHESSBOARD_H */
ChessBoard.cpp:
#include "ChessBoard.h"#include "Space.h"#include "Rook.h"using namespace std;ChessBoard::ChessBoard() { Rook brookL(); board[0][0].setPIEceObj(&brookL);}
Rook.h:
#ifndef ROOK_H#define ROOK_H#include "PIEce.h"using namespace std;class Rook : public PIEce {public: Rook() : PIEce() { }};#endif /* ROOK_H */
PIEce.h:
#ifndef PIECE_H#define PIECE_Husing namespace std;class PIEce {public: PIEce() { }};#endif /* PIECE_H */
Space.h:
#ifndef SPACE_H#define SPACE_H#include "PIEce.h"#include "Rook.h"using namespace std;class Space {private: PIEce *pIEceObj;public: voID setPIEceObj(PIEce &);};#endif /* SPACE_H */
Space.cpp:
#include "Space.h"using namespace std;Space::Space() {}voID Space::setPIEceObj(PIEce &p) { pIEceObj = p;}
请帮忙.谢谢.
解决方法 基于对代码的检查,似乎setPIEceObj()应该采用指针参数:voID Space::setPIEceObj(PIEce *p) { pIEceObj = p;}
这是一个问题.现在,您需要将指针传递给PIEce对象.
Rook brookL();board[0][0].setPIEceObj(&brookL);
这是一个most vexing parse,它声明一个返回Rook的函数,并将指针传递给setPIEceObj().
没有足够的信息来确定您的明确意图.也许:
Rook brook;board[0][0].setPIEceObj(&brookL);总结
以上是内存溢出为你收集整理的C多态性错误:没有匹配函数用于调用全部内容,希望文章能够帮你解决C多态性错误:没有匹配函数用于调用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)