I get the error:
error C2512: 'Mouse' : no appropriate default constructor available
Error executing cl.exe.
in the following code, and I can't figure out why the class Mouse default constructor is called:
Code:
#include <iostream>
using namespace std;
class Mouse
{
public:
Mouse(int n)
{
length = n;
}
void Display()
{
cout<<length<<endl;
}
int GetLength()
{
return length;
}
private:
int length;
};
class Cat
{
public:
Cat(Mouse m)//********ERROR
{
member1 = m;
}
void Display()
{
cout<<member1.GetLength()<<endl;
}
private:
Mouse member1;
};
int main()
{
Mouse my_Mouse(3);
Cat my_Cat(my_Mouse);
my_Cat.Display();
return 0;
}
If I add a default constructor to class Mouse, then it works fine. When is the default constructor called?