我只是在做我的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|


这是我的AnimationSet:

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;
}

最佳答案

您提供的代码没有显示错误的位置,但是我想您在AnimationSet中有一个drawObject成员对象,这意味着,在没有默认构造函数的情况下,您必须在构造函数中对其进行初始化初始化列表。

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/

10-11 19:33