我在动态库中有一个带有public函数的类:

void setActiveAnimation(std::shared_ptr<MaJR::Animation> anim);

当我尝试这样称呼它时:
    MaJR::Actor actor;
    actor.setActiveAnimation(idleAnimation);

我得到以下内容:
/home/mike/NixCraft/main.cpp||In function 'int main()':|
/home/mike/NixCraft/main.cpp|12|error: no matching function for call to 'MaJR::Actor::setActiveAnimation(MaJR::Animation&)'|
/home/mike/NixCraft/main.cpp|12|note: candidate is:|
/usr/include/MaJR/Actor.hpp|16|note: void MaJR::Actor::setActiveAnimation(std::shared_ptr<MaJR::Animation>)|
/usr/include/MaJR/Actor.hpp|16|note:   no known conversion for argument 1 from 'MaJR::Animation' to 'std::shared_ptr<MaJR::Animation>'|
||=== Build finished: 4 errors, 0 warnings ===|

我该怎么办?

最佳答案

该错误清楚地表明您正在尝试使用对MaJR::Animation而不是std::shared_ptr<MaJR::Animation>的引用来调用该函数。每当声明idleAnimation时,您都应该改为:

std::shared_ptr<MaJR::Animation> idleAnimation( new MaJR::Animation() );

或更好:
std::shared_ptr<MaJR::Animation> idleAnimation = std::make_shared<MaJR::Animation>();

07-28 14:03