2.4.6 override
Name
override
Description
Use the override modifier to extend or modify the abstract or virtual implementation of an inherited method, property.
Remark
You can't override a non-virtual or static method. The overridden base method must be virtual, or override.
You can't use the new, static, or virtual modifiers to modify an override method.
An overriding property declaration must specify exactly the same access modifier, type, and name as the inherited property.
Examples
EX1
- This example with compile error shows how to use override correctly
class CTestBase { public: virtual void TestV() { printf("CTestBase::TestV\r\n"); } virtual void TestV(int aa) { printf("CTestBase::TestV with int\r\n"); } void TestNonV() { printf("CTestBase::TestNonV\r\n"); } }; class CTestObj : public CTestBase { public: CTestObj() override // compile error { } void TestV() override; void TestV(int aa, double dd) override // compile error { } void Test1() override // compile error { } }; void CTestObj::TestV() override // compile error { } //void CTestObj::Test1() //{ //} void test_override() override // compile error { CTestObj obj; obj.TestV(); }