Jump to content
  • Advertisement
Sign in to follow this  
Aluthreney

"no matching function for call to" error: Help

This topic is 2487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm developing a music player using SDL and I'm having some trouble figuring out how to solve an error(s) I'm getting. The actual code is quite large and most of it has nothing to do with the problem so I wrote a new program that simulates the original problem.


#include <iostream>
#include <string>
using namespace std;
class Animal
{
protected:
int age;
int weight;
string name;
public:
Animal(int AGE, int WEIGHT, string NAME)
{
age=AGE;
weight=WEIGHT;
name=NAME;
}
void Sleep()
{
cout << "Animal is sleeping...\n";
}
void Eat()
{
cout << "Animal is eating...\n";
}
void Play()
{
cout << "Animal is playing...\n";
}
};
class Cat:public Animal
{
public:
Cat(int AGE, int WEIGHT, string NAME)
{
age=AGE;
weight=WEIGHT;
name=NAME;
}
};
int main()
{

}


These are the errors I get:
line 40 error: no matching function for call to 'Animal:Animal()'
line 40 note: candidates are:
line 13 note: Animal(int, int std::string)
line 13 note candidate expects 3 arguments, o provided
line 5 note: Animal::Animal(const Animal&)
line 5 note: candidate expects 1 argument, 0 provided

P.S. Not sure if it matters but I'm using Code::Blocks.

Share this post


Link to post
Share on other sites
Advertisement
Your derived class should not initialize the base class. Your error is because before the derived constructor is called, the base class constructor is called, but as Tribad said, you're trying to default initialize the base class but there is no default constructor for the base class. Instead, forward the parameters to the base class constructor, and leave the derived class constructor empty if you have no additional construction to do in the derived class.
[source]
class Cat:public Animal
{
public:
Cat(int AGE, int WEIGHT, string NAME) : Animal(AGE, WEIGHT, NAME) {}
};

[/source]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!