Last active
August 29, 2015 14:07
-
-
Save TSKGunGun/baf6633f0076ef8aa0fd to your computer and use it in GitHub Desktop.
override修飾子をつかってみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<string> | |
using namespace std; | |
namespace Hogehoge{ | |
//@super class | |
class SuperClass | |
{ | |
public : | |
string Func( int n ){ | |
return "SuperFunc"; | |
} | |
virtual string VirtualFunc( int n ){ | |
return "VirtualSuperFunc"; | |
} | |
}; | |
//@inheritance class | |
class ChildClass : public SuperClass | |
{ | |
public : | |
//@override | |
virtual string Func( int n ) override { //エラー! | |
return "ChildClass"; | |
} | |
//@override | |
virtual string VirtualFunc( int n ) override { //オッケー! | |
return "ChildClass-Virtual"; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
override修飾子をつけることでオーバーライドの明示化ができる。
virtualではないメソッドはoverrideできない。コンパイルエラーになる。
結構便利
Javaのfinal~とかはC++11でできるけど、VS2010は未対応(ビルドできない)