有时我会使用CRTP编写如下代码:
// this was written first
struct Foo : Base<Foo, ...>
{
...
};
// this was copy-pasted from Foo some days later
struct Bar : Base<Foo, ...>
{
...
};
而且很难理解出了什么问题,直到我在调试器中跟踪代码并看到 Bar 的成员没有在Base
.
如何在编译时显示此错误?
(我用的是MSVC2010,所以可以使用一些C++0x特性和MSVC语言扩展)