【发布时间】: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 被设置为指向继承自Animation 的Raindrops 类的一个实例:
animationPointer = &raindrops;
原来的定义是:
Animation *animationPointer;
就我(有限!)对指针的理解而言,这应该有效:raindrops 应该位于animationPointer 指向的地址,然后-> 应该给出animate 方法的结果.所以我不确定为什么编译器将调用视为具有通过引用传递的参数。
令人困惑的是,我有非常相似的代码假定可以工作(我没有办法对此进行测试,它是一个嵌入式应用程序,我正在将代码从一种 MCU 类型转换为另一种)。
【问题讨论】:
标签: c++ pointers compiler-errors member-function-pointers