开发者

static_assert not working in Visual C++ 10

开发者 https://www.devze.com 2023-03-18 03:53 出处:网络
I was under impression Visual C++ 10 had built-in static_assert. However when I compile the following

I was under impression Visual C++ 10 had built-in static_assert. However when I compile the following

v开发者_运维知识库oid test()
{
    static_assert( sizeof( char ) == 1, "" );
}

I get

error C3861: 'static_assert': identifier not found

What am I doing wrong and how do I use static_assert in Visual C++ 10?


I was under impression Visual C++ 10 had built-in static_assert.

It indeed does and this compiles perfectly fine for me:

int main(){
    static_assert( sizeof( char ) == 1, "" );
}

Do you have any other errors in your code? Maybe this error is a result of the chain of other erros.


The reason was Visual Studio was set up to use Visual C++ 9 compiler (the one which is shipped with Visual Studio 2008). I don't know how it happened, perhaps the wizard configuring Visual Studio imported paths to the previous version.

The settings is changed in project properties - on "VC++ Directories" pane. The easy way to check which compiler is invoked is to add -Bv option to the compiler command line which will make the compiler report its version.

0

精彩评论

暂无评论...
验证码 换一张
取 消