VS 2010 C ++ IntelliSense“此处可能未指定存储类".即使可以呢? [英] VS 2010 C++ IntelliSense "a storage class may not be specified here" even though it can?

查看:152
本文介绍了VS 2010 C ++ IntelliSense“此处可能未指定存储类".即使可以呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个相当小的问题,但是让我很烦:IntelliSense似乎确信在if条件下在功能范围内声明 的静态变量是一个错误,并且对此有所抱怨. .只有它可以很好地构建,甚至MSDN文档都将其称为合法用法.我真的想摆脱波浪形的红线,因为它经常出现(它在我经常使用的宏中使用).

This is a fairly minor question, but it's annoying me: IntelliSense seems to be convinced that declaring static variables at the function-scope in an if condition is an error, and complains about it. Only it builds just fine, and even the MSDN docs mention it as a legitimate usage. I'd really like to get rid of the wavy red line, because it comes up fairly often (it's used in a macro I use regularly).

以下是示例代码,虽然它不是我程序中的唯一示例:

Here's the code, as an example, though it's not the only example in my program:

MyForm::MyForm()
{
    _VMESSAGE("Constructing '%s'/%p:%p @ <%p>",GetEditorID(),GetFormType(),formID,this);
    if (static bool runonce = true)
    {
        // patch up vtbl    
        memaddr thisvtbl = (UInt32)memaddr::GetObjectVtbl(this);
        _MESSAGE("Patching MyForm Form vtbl @ <%p>",thisvtbl);
        gLog.Indent();
        for (int i = 0; i < sizeof(Form_NoUseMethods)*0x8; i++)
        {
            if ((Form_NoUseMethods[i/0x20] >> (i%0x20)) & 1)
            {
                thisvtbl.SetVtblEntry(i*4,TESForm_vtbl.GetVtblEntry(i*4));
                _VMESSAGE("Patched Offset 0x%04X",i*4);
            }
        }
        gLog.Outdent();

        runonce  =  false;
    }
}

if ( static bool runonce = true )行中的static_MESSAGE_VMESSAGE的每种用法(都使用类似的构造)都由IntelliSense强调,并悬停在所有读取上错误:存储类可能不在此处指定."构建项目不会产生与这些行有关的错误.

Both the static in the if ( static bool runonce = true ) line and every usage of _MESSAGE or _VMESSAGE (which uses a similar construct) is underlined by IntelliSense, and hovering over any reads "Error: a storage class may not be specified here." Building the project produces no errors relating to these lines.

推荐答案

VC ++编译器允许将此作为​​静默扩展(它不是合法的C ++),但是VC ++ IntelliSense引擎基于

The VC++ compiler allows this as a silent extension (it is not legal C++), but the VC++ IntelliSense engine is based on the EDG compiler frontend, not the VC++ compiler (go figure). So, the IntelliSense error is correct if you're concerned about writing portable code.

这篇关于VS 2010 C ++ IntelliSense“此处可能未指定存储类".即使可以呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆