我有一个带有构造函数的AdventureGame类。当我尝试制作新的AdventureGame对象时,收到错误消息“没有匹配函数调用'AdventureGame :: AdventureGame()”

这是我的一些类,构造函数和main。

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

class AdventureGame
{
private:
public:
    int playerPos;
    int ogrePos;
    int treasurePos;
    string location;

    AdventureGame(int ogre, int treasure)
    {
        playerPos = -1;
        ogrePos = ogre;
        treasurePos = treasure;
        location = "";
    };

.
.
.  // other functions that I'm sure are irrelevant
.
.

    int main()
    {
        AdventureGame game;
        int numMoves = 0;
        std::string move;

        while (!game.isGameOver(game.playerPos))
        {
            game.printDescription(game.playerPos);
            cout << "Which direction would you like to move? (forward, left, or right)" << endl;
            cin >> move;
            game.move(move);
            numMoves++;
        }
    }


如何创建新游戏?

最佳答案

您的构造函数期望您需要传递两个参数。

像这样:

AdventureGame游戏(3,5);

10-06 01:00