未显式指定要在派生类中重写的方法.这应该行得通吗
Not explicitly specifying method to be overriden in derived class. Is this supposed to work?
用代码比用文字更好地解释:
//Classes.hpp
struct Base
{
virtual void foo() = 0;
};
struct Derived : public Base
{
//Nothing here
};
//Classes.cpp
void Derived::foo()
{
//Do something here
}
我看到这个编译没有错误,但奇怪的是,你不必在Derived类中明确声明你要实现"foo"。
这应该按照C++标准工作吗?
不知道您使用的是什么编译器,但这不是合法的c++。我的VC和gcc在编译此代码时返回预期的错误。
相关文章:
- 在模板基类中为继承类中的可选重写生成虚拟方法
- 方法重写线程C++中的概念
- 如何强制从重写方法调用重写的方法基方法?
- 如何重写全局方法名称以在调用原始方法之前将我的代码推到前面
- C++有没有办法强制重写一组方法,如果其中一个方法在子类中具有重写?
- 在 C++ 中使用模板方法重写类方法
- 检查子类是否执行了方法重写
- C++方法重写和重载(编译器级别)
- 用模板方法重写虚拟方法
- 方法重写(没有虚拟方法或指针)是否被认为是多态性的一部分
- C++ - 方法重写未按预期表示
- 使用两种方法重写<<运算符
- C++阻止方法重写
- C++方法重写
- c++在具体类中强制方法重写
- 方法重载和方法重写的性能问题
- C++中的方法重写是否总是在派生类的标头中完成?
- 是否有更好的方法重写此代码片段
- 为什么静态方法重写基类非静态方法
- 方法重写