c++ - 库中没有匹配的调用函数

标签 c++

我在动态库中有一个带有公共(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>();

关于c++ - 库中没有匹配的调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10957303/

相关文章:

c++ - Make 找不到我的 .so.2.4.8 文件

C++ 将枚举传递给对象构造函数

c++ - 继承类中的构造函数调用

C++ Linux - 将时区更改为某个时区

java - 在不更改 C++ 代码的情况下从 Java 调用 C++ 函数

c++ - ODBC 写入 blob 示例 Oracle C++

c++ - 为什么这个 constexpr 函数格式错误?

C++ 指针与取消引用的对象

c++ - 将值添加到单独链接的哈希表 C++

c++ - 让 Chrono C++ 库 (Boost::sandbox) 工作