The*_* do 1 c++ polymorphism abstract-class
假设我上课了:
class Bad_Date
{
private:
const char* _my_msg;
public:
const char* msg() const
{
return _my_msg;
}
};
Run Code Online (Sandbox Code Playgroud)
我想不能创建这个类的任何对象,但我真的不想在那里放任何其他东西,并使其成为纯虚拟fnc.有没有其他方法可以使这个类抽象或我必须创建虚拟fnc并将其声明为纯虚拟?谢谢.
使构造函数受到保护:
class Bad_Date
{
private:
const char* _my_msg;
// Add the 2 lines below:
protected:
Bad_Date() {}
public:
const char* msg() const
{
return _my_msg;
}
};
Run Code Online (Sandbox Code Playgroud)