如何在 C++11 中定义强 ID 类型?可以完成整数类型的别名,但在混合类型时会收到编译器的警告?
例如:
using monsterID = int;
using weaponID = int;
auto dragon = monsterID{1};
auto sword = weaponID{1};
dragon = sword; // I want a compiler warning here!!
if( dragon == sword ){ // also I want a compiler warning here!!
// you should not mix weapons with monsters!!!
}