c++ - 没有匹配函数调用 'AnimationSet::AnimationSet()'

标签 c++ function call match

我只是在做我的 DrawObject 构造函数,并不断遇到这个错误:

C:\CodeBlocks\SDLGame\DrawObject.cpp|3|error: no matching function for call to 'AnimationSet::AnimationSet()'|
C:\CodeBlocks\SDLGame\DrawObject.cpp|3|note: candidates are:|
C:\CodeBlocks\SDLGame\AnimationSet.h|9|note: AnimationSet::AnimationSet(int)|
C:\CodeBlocks\SDLGame\AnimationSet.h|9|note:   candidate expects 1 argument, 0 provided|
C:\CodeBlocks\SDLGame\AnimationSet.h|5|note: AnimationSet::AnimationSet(const AnimationSet&)|
C:\CodeBlocks\SDLGame\AnimationSet.h|5|note:   candidate expects 1 argument, 0 provided|

这是我的动画集:

class AnimationSet
{
    public:

        AnimationSet(int animationCounter);
        virtual ~AnimationSet();
        int getCurrentFrame();
        void setCurrentFrame(int currentFrame);
        int getCurrentAnimation();
        void setCurrentAnimation(int currentAnimation);

    private:

        int currentFrame;
        int curretAnimation;
        Animation* animations;
};

我的 drawObject 构造函数:

drawObject::drawObject(char* name, char* surfaceFile, int xPos, int yPos, int drawLevel, bool willMoveVar, bool isSpriteVar, int animationNumber)
{
    animationSet = new AnimationSet(animationNumber);
    name = name;
    xPos = xPos;
    yPos = yPos;
    willMoveVar = willMove;
}

最佳答案

你提供的代码没有显示错误在哪里,但我猜你在drawObject中有一个AnimationSet成员对象,这意味着,在没有对于默认构造函数,您必须在构造函数初始化列表中对其进行初始化。

drawObject::drawObject(char* name, char* surfaceFile, int xPos, int yPos, int drawLevel, bool willMoveVar, bool isSpriteVar, int animationNumber) :
animationSet(animationNumber) //I'm assuming this isn't a pointer
{
  name = name;
  xPos = xPos;
  yPos = yPos;
  willMoveVar = willMove;
}

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

相关文章:

c++ - C++中的设计问题

JAVA整数问题

loops - 遍历所有子文件夹并执行bat文件?

c++ - 解析命令行参数和响应文件

c++ - QString: 最多 2 位小数的数字,后面不带零

c++ - std::vector 覆盖最终值,而不是增长?

c - 分配适当的变量以使这些声明正确

sql-server - 如何在 SQL Server 中加密函数

swift - 使函数能够处理不同的类作为参数

android - 为什么我的应用程序不调用电话?