【发布时间】:2014-01-30 03:25:15
【问题描述】:
所以我正在制作一个程序,它将找到一个拼字游戏的所有可能单词(由字典定义)(如果你不知道它是什么,请谷歌它)。无论如何,我有 3 个类/对象:字典、游戏板和 bogglegame。 bogglegame 应该梳理字典和游戏板并找到所有合法单词。我的 bogglegame 构造函数看起来像
BoggleGame::BoggleGame(Dictionary dictionaryIN, GameBoard gameboardIN)
Dictionary 和 GameBoard 的构造器看起来像
Dictionary::Dictionary(set<string> wordsInDictionaryIN, unsigned maxLengthIN)
GameBoard::GameBoard(vector<vector<string> > gamestateIN, unsigned boardSizeIN)
当我尝试编译时,我收到一条错误消息,提示“错误:没有匹配函数调用‘Dictionary::Dictionary()”
我希望能够将字典和游戏板对象从 main 传递到构造函数中,并将它们存储为 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;
};
【问题讨论】:
-
你能发布给出错误的行吗?
-
您正在尝试在某处调用默认 ctor(
Dictionary::Dictionary()所指的任何行),但您有一个用户定义的 ctor,因此它会抑制默认 ctor 的生成。
标签: c++ object constructor