【问题标题】:C++ - no matching function for call to <class method>C++ - 没有用于调用 <class method> 的匹配函数
【发布时间】:2014-07-31 23:58:34
【问题描述】:

我从下面的代码中得到下面的编译器错误。

cube.cpp:94: error: no matching function for call to 'Animation::animate(CUBE_ARRAY&, uint8_t&, uint8_t&, CUBE_STATE&)'
animation.h:28: note: candidates are: virtual uint8_t Animation::animate(CUBE_ARRAY*, uint8_t, uint8_t, CUBE_STATE)

有一个类Animation有一个方法:

28 virtual uint8_t animate(CUBE_ARRAY *arrayP, uint8_t transIn, uint8_t transOut, CUBE_STATE startState);

这是由线路调用的:

94 animationComplete = animationPointer -> animate(cubeArray, transIn, transOut, state);

animationPointer 被设置为指向继承自AnimationRaindrops 类的一个实例:

animationPointer = &raindrops;

原来的定义是:

Animation *animationPointer;

就我(有限!)对指针的理解而言,这应该有效:raindrops 应该位于animationPointer 指向的地址,然后-&gt; 应该给出animate 方法的结果.所以我不确定为什么编译器将调用视为具有通过引用传递的参数。

令人困惑的是,我有非常相似的代码假定可以工作(我没有办法对此进行测试,它是一个嵌入式应用程序,我正在将代码从一种 MCU 类型转换为另一种)。

【问题讨论】:

    标签: c++ pointers compiler-errors member-function-pointers


    【解决方案1】:

    错误信息提示你应该这样做

    animationComplete = animationPointer->animate(
        &cubeArray, transIn, transOut, state);
    

    注意cubeArray前面的&。

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 2014-11-29
      • 1970-01-01
      • 1970-01-01
      • 2021-09-21
      • 2016-11-23
      • 2012-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多