因此,我正在製作一個程序,它將查找所有可能的單詞(由字典定義)的一個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。 –