Okay I'm not sure how to explain this but here goes. I want to get name (from return name) for both the Dog and Cat classes into int main so that they print out where fido.name and spot.name are. How would I do this?
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class Dog {
private:
// constructor
Dog(string name) {
this->name = name;
name = "Fido";
cout << "Dog's name is " << name << endl;
}
public:
static string name;
static string GetName();
};
string Dog::GetName(){
return name;
}
class Cat {
private :
// constructor
Cat(string name) {
this->name = name;
name = "Fido";
cout << "Cat's name is " << name << endl;
}
public :
static string name;
static string GetName();
};
string Cat::GetName(){
return name;
}
int main() {
Dog fido("Fido"); //error here stating that Dog::Dog(std::string name)
//declared at line 13 is inaccessible
Cat spot("Spot");
cout << "From main, the Dog's name is " << fido.name << endl;
cout << "From main, the Cat's name is " << spot.name << endl;
cout << "Hit any key to continue" << endl;
system("pause");
return 0;
}