更重要的是,这段代码有什么问题:
#include <assert.h>
#include <functional>
using namespace std;
template< class BaseObjectId >
class Check
{
protected:
Check( function<bool()> const f ) { assert( f() ); }
};
template< int tpMinValue, int tpMaxValue >
class IntegerSubrange
: private Check< IntegerSubrange< tpMinValue, tpMaxValue > >
{
private:
int value_;
public:
enum :int { minValue = tpMinValue, maxValue = tpMaxValue };
static bool rangeContains( int const x )
{
return (minValue <= x && x <= maxValue);
}
operator int() const
{
return value_;
}
void operator/=( int const rhs )
{
value_ /= rhs;
assert( rangeContains( value_ ) );
}
explicit IntegerSubrange( int const value )
: Check< IntegerSubrange< tpMinValue, tpMaxValue > >(
[=]() -> bool { return rangeContains( value ); }
)
, value_( value )
{}
};
int main() {}
Visual C++ 报告语法错误:
foo.cpp foo.cpp(41):错误 C2059:语法错误:')' foo.cpp(44) : 请参阅正在编译的类模板实例化“IntegerSubrange”的参考 foo.cpp(42):错误 C2059:语法错误:',' foo.cpp(43) : 错误 C2334: '{' 之前的意外标记;跳过明显的函数体