VS 2010 C++ IntelliSense“此处不能指定存储类别”即使可以吗?
这是一个相当小的问题,但它让我很恼火:IntelliSense 似乎确信在 if
条件中声明静态变量 在函数范围 是一个错误,并抱怨关于它。只有它构建得很好,甚至 MSDN 文档也提到它是合法的用法。我真的很想去掉红色波浪线,因为它经常出现(它在我经常使用的宏中使用)。
这是代码,作为示例,尽管它不是我的程序中的唯一示例:
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 加上下划线,并将鼠标悬停在任何内容上“错误:此处可能未指定存储类”。构建项目不会产生与这些行相关的错误。
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;
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
VC++ 编译器允许将此作为静默扩展(它不是合法的 C++),但 VC++ IntelliSense 引擎基于 EDG 编译器前端,而不是 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.
等等——您是说下面的代码在 MSVC 中编译并运行吗?
这对我来说是一种新的体验。 g++ 当然不接受它。
顺便说一句,在您的问题中,您提到“在函数范围内声明静态变量”,这不是问题:
Hold on -- are you saying that the following code compiles and runs in MSVC?
That's a new one on me. g++ certainly doesn't accept it.
BTW, in your question, you mention "declaring static variables at the function-scope", which is not a problem: