C++ 无法从std::shared\u ptr<;转换参数1_Ty>;(??)

C++ 无法从std::shared\u ptr<;转换参数1_Ty>;(??),c++,C++,在完成我的游戏原型时,我遇到了这个错误,我以前从未见过它。 我试图将两个.cpp文件链接在一起,如下所示: #include <iostream> #include "mage.h" #include "Warrior.h" #include "Rogue.h" #include "CharacterType.h" #include <memory> #include <string> #incl

在完成我的游戏原型时,我遇到了这个错误,我以前从未见过它。 我试图将两个.cpp文件链接在一起,如下所示:

    #include <iostream>
    #include "mage.h"
    #include "Warrior.h"
    #include "Rogue.h"
    #include "CharacterType.h"
    #include <memory>
    #include <string>
    #include "Inventory.h"
    #include "blankEnemy.h"
    #include "Enemy.h"
    #include "Boss.h"
    #include <cstdlib>
    #include <ctime>
    #include "DeathMenu.h"
    #include "GameStart.h"
    #include "FirstPhase.h"
    #include <Windows.h>
    #include "SecondPhase.h"
    #include "PhaseOnePT2.h"
    using namespace std;

    int FirstPhase(blankCharacter* myCharacter, blankEnemy* myEnemy, Inventory* myInventory,       blankEnemy* myBoss)
    {
     //code
    }
没有合适的转换从共享_ptr到*blankCharacter exists'?
我不知道怎么解决它

C++11智能指针不提供与原始指针类型之间的自动转换(出于安全原因)。使用:


更好的做法是,将函数更改为接受引用而不是指针(或者它是否正确处理传入的空值?),然后在调用站点取消对指针的引用。

您应该使用
get()
提取底层指针,或者将原型更改为在函数调用中使用智能指针:

choice = FirstPhase(myCharacter.get(), myEnemy.get(), myInventory.get(), myBoss.get());

顺便说一句,你应该发布完整的错误。在那里的某个地方,它还表示
\u Ty
代表什么。
    #include "GameStart.h"
    #include <string>
    #include "CharacterType.h"
    #include "mage.h"
    #include "Rogue.h"
    #include "Warrior.h"
    using namespace std;
    int FirstPhase(blankCharacter* myCharacter, blankEnemy* myEnemy, Inventory* myInventory, blankEnemy* myBoss);
  choice = FirstPhase(myCharacter, myEnemy, myInventory, myBoss);
choice = FirstPhase(myCharacter.get(), myEnemy.get(), myInventory.get(), myBoss.get());
choice = FirstPhase(myCharacter.get(), myEnemy.get(), myInventory.get(), myBoss.get());