C++11
final针对虚函数,拒绝重载,某些情况下,拒绝被重载
加了final关键字的虚函数,无法被重写,预留接口
//error C3248: “ye::print”: 声明为“final”的函数无法被“ba::print”重写
1 #include <iostream> 2 3 //final拒绝重载,某些情况下,拒绝被重载 4 5 class ye 6 { 7 public: 8 virtual void print() final 9 { 10 std::cout << "爷爷" << std::endl; 11 } 12 }; 13 14 class ba :public ye 15 { 16 public: 17 void print()//error C3248: “ye::print”: 声明为“final”的函数无法被“ba::print”重写 18 { 19 std::cout << "爸爸" << std::endl; 20 } 21 }; 22 23 void main() 24 { 25 26 system("pause"); 27 }