When I try to run my program it prints out
"error: no matching function for call to
Dog::Dog(const char [4], const char [5])
".
This occurs at line 60 and 61. Is it reading the arguments as a C-String? I should still be able to pass it into the constructor, can't I?
#include <iostream>
#include <string>
using namespace std;
#include <string>
class Pet
{
protected:
string type;
string name;
public:
Pet(const string& arg1, const string& arg2);
virtual void whoAmI() const;
virtual string speak() const = 0;
};
Pet::Pet(const string& arg1, const string& arg2): type(arg1), name(arg2)
{}
void Pet::whoAmI() const
{
cout << "I am an excellent " << type << " and you may refer to me as " << name << endl;
}
class Dog : public Pet
{
public:
void whoAmI() const; // override the describe() function
string speak();
};
string Dog::speak()
{
return "Arf!";
}
class Cat : public Pet
{
string speak();
// Do not override the whoAmI() function
};
string Cat::speak()
{
return "Meow!";
}
ostream& operator<<(ostream& out, const Pet& p)
{
p.whoAmI();
out << "I say " << p.speak();
return out;
}
int main()
{
Dog spot("dog","Spot");
Cat socks("cat","Socks");
Pet* ptr = &spot;
cout << *ptr << endl;
ptr = &socks;
cout << *ptr << endl;
}
Any help is greatly appreciated!