因此,我正在制作一个程序,它将查找所有可能的单词(由字典定义)的一个boggle游戏(谷歌它,如果你不知道它是什么是)。无论如何,我有3类/对象:字典,游戏板和bogglegame。 bogglegame应该梳理字典和游戏板,并找到所有合法的单词。我对bogglegame构造看起来像用另一个对象作为参数在构造函数中创建一个对象
BoggleGame::BoggleGame(Dictionary dictionaryIN, GameBoard gameboardIN)
和词典和游戏键盘的contsrtuctors样子
Dictionary::Dictionary(set<string> wordsInDictionaryIN, unsigned maxLengthIN)
GameBoard::GameBoard(vector<vector<string> > gamestateIN, unsigned boardSizeIN)
,当我尝试编译我得到,说:“错误的错误:没有匹配函数调用'Dictionary :: Dictionary()“
我想能够通过在词典ry和gameboard对象从主存入到构造函数中,并将它们存储为BoggleGame对象的私有成员,使BoggleGame对象成为2个对象的对象。
编辑:邮政代码
构造BoggleGame
#include "BoggleGame.h"
BoggleGame::BoggleGame(Dictionary dictionaryIN, GameBoard gameboardIN)
{
dictionary = dictionaryIN;
gameboard = gameboardIN;
}
#pragma once
#include "Dictionary.h"
#include "GameBoard.h"
class BoggleGame
{
public:
BoggleGame(Dictionary dictioanryIN, GameBoard gameboardIN);
void foundWord(string wordIN);
string findTheWords(string w, unsigned row, unsigned column);
set<string> getTheFoundWords() {return foundWords;}
bool isInDictionary(string word);
bool isOffBoard(unsigned row, unsigned column);
bool usedTile(unsigned row, unsigned column);
vector<vector<string> > getTheGameBoard(){gameboard.getGameBoard();}
private:
Dictionary dictionary;
GameBoard gameboard;
set<string> foundWords;
};
#pragma once
#include <set>
#include <vector>
#include <string>
#include <iterator>
using std::set;
using std::string;
using std::vector;
class Dictionary
{
public:
Dictionary(set<string> wordsInDictionaryIN, unsigned maxLengthIN);
bool isInDictionary(string wordIN);
void foundWord (string wordIN);
string findTheWords(string w, unsigned row, unsigned column);
unsigned getMaxLength() {return maxLength;}
private:
set<string> wordsInDictionary;
unsigned maxLength;
set<string> foundWords;
};
#pragma once
#include <vector>
#include <string>
using std::string;
using std::vector;
class GameBoard
{
public:
GameBoard(vector<vector<string> > gamestateIN, unsigned boardSizeIN);
bool outOfBoard(unsigned row, unsigned column);
bool getTileUseState(unsigned row, unsigned column){return usedTiles.at(row).at(column);}
void setTileUsed(unsigned row, unsigned column);
vector<vector<string> > getGameBoard(){return gamestate;}
unsigned getSize(){return boardSize;}
vector<vector<bool> > getUsedTiles() {return usedTiles;}
string readTile(unsigned row, unsigned column) {return gamestate.at(row).at(column);}
void previousState(vector<vector<bool> > previous) {usedTiles = previous;}
private:
vector<vector<string> > gamestate;
vector<vector<bool> > usedTiles;
unsigned boardSize;
};
你可以发布给出错误的行吗? – Brian
你正在尝试在某处调用默认的ctor(无论'Dictionary :: Dictionary()'所指的行是什么),但是你有一个用户定义的ctor,所以它禁止生成默认的ctor。 –