Hi,
I know it isn't used but for completness....Why compiler says I can't instantiate it? I've publicized it in the derived class; doesn't it should work?
Pet* p = new Cat;
#ifndef PET2_H
#define PET2_H
using std::string;
using std::cout;
class Pet {
public:
Pet() { speak(); cout << "Pet::Pet()\n"; }
virtual ~Pet() = 0;
virtual string speak() { return "Pet "; }
};
inline Pet::~Pet() { speak(); cout << "Pet::~Pet()\n"; }
class Cat : private Pet {
char* _ver;
public:
Pet::Pet;
Cat() : _ver( new char('q') /* 1 */ ) { cout << "Cat::Cat()\n";}
~Cat() { cout << "Cat::~Cat()\n"; delete _verso; }
string speak() { return "Cat: bark, bark\n"; }
};
#endif PET2_H
error C2243: 'type cast' : conversion from 'Cat *' to 'Pet *' exists, but is inaccessible
Pet* p = new Cat;
#ifndef PET2_H
#define PET2_H
using std::string;
using std::cout;
class Pet {
public:
Pet() { speak(); cout << "Pet::Pet()\n"; }
virtual ~Pet() = 0;
virtual string speak() { return "Pet "; }
};
inline Pet::~Pet() { speak(); cout << "Pet::~Pet()\n"; }
class Cat : private Pet {
char* _ver;
public:
Pet::Pet;
Cat() : _ver( new char('q') /* 1 */ ) { cout << "Cat::Cat()\n";}
~Cat() { cout << "Cat::~Cat()\n"; delete _verso; }
string speak() { return "Cat: bark, bark\n"; }
};
#endif PET2_H
error C2243: 'type cast' : conversion from 'Cat *' to 'Pet *' exists, but is inaccessible
To copy to clipboard, switch view to plain text mode
furthermore: in /* 1 */ i'd like to initialize with a string. Which sintax, please?
Bookmarks