C++ C+有错误+;游戏,I';我很确定这是';指针有问题。但我说不出来

C++ C+有错误+;游戏,I';我很确定这是';指针有问题。但我说不出来,c++,mud,C++,Mud,我不知道你如何解决这个问题。它一直告诉我我没有匹配的函数可以调用,它一直说参数1从'Npc**'到'Npc**'没有已知的转换* 具体来说,它是说handleDialogueTwo(非层)有一个问题;和handleDialogueThree(&nonplayer) 我肯定这是一个愚蠢的解决方案,但我已经为它挠头了,并且把事情拖来拖去好几个小时了。请帮忙 void Dungeon::handleRoomWithNpc(Room * room) { Npc nonplayer = room-

我不知道你如何解决这个问题。它一直告诉我我没有匹配的函数可以调用,它一直说参数1从'Npc**'到'Npc**'没有已知的转换*

具体来说,它是说handleDialogueTwo(非层)有一个问题;和handleDialogueThree(&nonplayer)

我肯定这是一个愚蠢的解决方案,但我已经为它挠头了,并且把事情拖来拖去好几个小时了。请帮忙

void Dungeon::handleRoomWithNpc(Room * room) {
    Npc nonplayer = room->nonplayer.front();
    cout << "Inside, you see a " << nonplayer.name << ".\n";
    string actions[] = {
        "a: Talk to " + nonplayer.name,
        "b: Fight " + nonplayer.name,
        "c: Leave",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
           handleDialogueOne(&nonplayer);
           return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer.attack);
            cout << nonplayer.name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else if (input == "c") {
            player.changeRooms(player.previousRoom);
            enterRoom(player.currentRoom);
            return;
        } else {
            cout << "Wrongo, Bucko.\n";
        }  
    }
}

void Dungeon::handleDialogueOne(Npc * nonplayer) {
    cout << nonplayer->dialogueOne;
    string actions[] = {
            "a: continue",
            "b: die",
            "c: fight",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
            handleDialogueTwo(&nonplayer);
            return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            }
        } else if (input == "c") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else {
            cout << "Wrongo, Bucko!\n";
        }
    }     
}

void Dungeon::handleDialogueTwo(Npc * nonplayer) {
    cout << nonplayer->dialogueTwo;
    string actions[] = {
            "a: continue",
            "b: die",
            "c: fight",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
            handleDialogueThree(&nonplayer);
            return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            }
        } else if (input == "c") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else {
            cout << "Wrongo, Bucko!\n";
        }
    }     
}

void Dungeon::handleDialogueThree(Npc * nonplayer) {
    cout << nonplayer->dialogueThree;
    string actions[] = {
            "a: continue",
            "b: die",
            "c: win",
        };
    while(true) {
        printActions(3, actions);
        string input;
        cin >> input;
        if (input == "a") {
            handleDialogueTwo(&nonplayer);
            return;
        } else if (input == "b") {
            int damage = player.takeDamage(nonplayer->attack);
            cout << nonplayer->name << " hits you for " << damage << " damage! \n";
            if (player.checkIsDead()){
            return;
            };
        } else if (input == "c") {
            nonplayer->currentHealth = 0;
            return;
        } else {
            cout << "Wrongo, Bucko!\n";
        }
    }     
}
void Dungeon::handleRoomWithNpc(房间*Room){
Npc nonplayer=room->nonplayer.front();

不能数据
nonplayer
具有类型
Npc*
,被调用方参数的类型也是
Npc*
,因此您不需要
handleDialogueTwo(&nonplayer);
handleDialogueTwo(&nonplayer)中的
handleDialogueTwo(&nonplayer)
。删除它们。

因此,当我这样做时,程序会直接崩溃并给我一个内存error@user9076567然后在代码中发现一个错误,但这是一个完全不同的问题。您得到的错误是一个非常基本的错误(初学者)编程错误。但是,我看到你已经有很多代码了!你不应该写很多代码然后开始测试。构建一点,测试,再构建一些,测试等等。或者你甚至可以先编写测试。此外,使用
NPC**
表明你可能没有使用正确的工具。它可能是repl由一个
std::vector
(甚至仅仅是一个
std::vector
)。如果函数接受指针参数,则通常最好测试是否获得
nullptr
。如果
nullptr
在程序中不是有效的情况,则通过引用获取参数,而不必测试
nullptr
。例如:
void Dungeon::handleRoomWithNpc(Room&Room)