Skip to content

Instantly share code, notes, and snippets.

@TSKGunGun
Last active August 29, 2015 14:07
Show Gist options
  • Save TSKGunGun/baf6633f0076ef8aa0fd to your computer and use it in GitHub Desktop.
Save TSKGunGun/baf6633f0076ef8aa0fd to your computer and use it in GitHub Desktop.
override修飾子をつかってみた
#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";
}
};
@TSKGunGun
Copy link
Author

override修飾子をつけることでオーバーライドの明示化ができる。
virtualではないメソッドはoverrideできない。コンパイルエラーになる。

結構便利

Javaのfinal~とかはC++11でできるけど、VS2010は未対応(ビルドできない)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment