【发布时间】:2012-07-02 07:04:51
【问题描述】:
更重要的是,这段代码有什么问题:
#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: '{' 之前的意外标记;跳过明显的函数体【问题讨论】:
-
啊,那我需要更新我的 g++。我也会用visual c ++ 11检查! 用 Visual C++ 11 编译得很好,我简直不敢相信
-
@Griwes:g++ 4.6.3 比 4.6.1 更新,4.6.1 编译 lambdas 就好了。
-
@Cheersandhth.-Alf,EitanT 链接了一个证明 4.3.4 无法编译它的证据 - 我指的是那个 - 现在已删除 - 评论。
-
其实compiles on gcc-4.5.1也是...
标签: c++ constructor lambda