导致“错误 C2856:#pragma hdrstop 不能位于 #if 块内”的原因在 VS C++ 中?
有一个程序我可以在2008年编译一段时间。 注意我可以使用 cl 在 Ultimate++ IDE 中编译该程序。 这是一个相当大的程序,所以我不打算将其发布在这里。 我无法在 Studio 中编译它。
这个错误
1>c:\program files\microsoft visual studio 9.0\vc\include\xstring(1735)
: error C2856: #pragma hdrstop cannot be inside an #if block
似乎很愚蠢,因为那里没有 hdrstop 。
预编译头已关闭。
这就是那里的内容:
if (_Mysize < _Off)
_String_base::_Xran(); // _Off off end
if (_Mysize - _Off < _Count)
_Count = _Mysize - _Off;
_Traits_helper::copy_s<_Traits>(_Dest, _Dest_size, _Myptr() + _Off, _Count);
return (_Count);
}
void __CLR_OR_THIS_CALL swap(_Myt& _Right)
{ // exchange contents with _Right <<<<<<<<----------this is the line
if (this == &_Right)
; // same object, do nothing
else if (_Mybase::_Alval == _Right._Alval)
{ // same allocator, swap control information
谢谢。
There was a program what I could compile under 2008 for a while.
Note I can compile the program using cl and in Ultimate++ IDE.
It is a fairly large program , so I am not going to post it here.
I cannot compile it in Studio.
The error is
1>c:\program files\microsoft visual studio 9.0\vc\include\xstring(1735)
: error C2856: #pragma hdrstop cannot be inside an #if block
which seems to be idiotic as there is no hdrstop in there.
Precompiled headers are turned off.
This is what is there:
if (_Mysize < _Off)
_String_base::_Xran(); // _Off off end
if (_Mysize - _Off < _Count)
_Count = _Mysize - _Off;
_Traits_helper::copy_s<_Traits>(_Dest, _Dest_size, _Myptr() + _Off, _Count);
return (_Count);
}
void __CLR_OR_THIS_CALL swap(_Myt& _Right)
{ // exchange contents with _Right <<<<<<<<----------this is the line
if (this == &_Right)
; // same object, do nothing
else if (_Mybase::_Alval == _Right._Alval)
{ // same allocator, swap control information
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现了这一点。它是由预编译头引起的,是的,但不需要关闭它。
当顶级
#include "headertobeprecompiled.h"
位于#if
#endif
块内时,就会发生这种情况。如果可以将其移到外面,错误消息就会消失。I found this out. It caused by precompiled headers, yes but there is no need to turn this off.
It happens when a top level
#include "headertobeprecompiled.h"
is inside an#if
#endif
block. If one can move it outside that the error message disappears.疯狂的猜测。
项目的预编译头已关闭?它们是否针对项目中的每个源文件关闭(导致单个文件设置覆盖整个项目设置)。
Wild guess.
The precompiled headers are switched off for the project? Are they switched off for every single source file in the project (cause individual file settings overwrite whole-project settings).
因为 Visual C++ 调用 cl (工作正常)并且您显然弄乱了标头,所以我要检查的第一件事是包含路径。将它们张贴在这里。
Because Visual C++ invokes cl (which works fine) and you obviously have messed up headers, the first thing I'd check are include paths. Post them here.
我遇到了完全相同的问题,并且也很困惑,因为我的代码中也没有任何 hdrstop 编译指示。但是,我从脚本(而不是 IDE)进行编译,当我省略编译器选项 /Yc(创建 PCH)时,错误消失。
I have experienced the exact same problem and was also puzzled since I don't have any hdrstop pragmas in my code, either. However, I compile from a script (not an IDE) and when I omit the compiler option /Yc (create PCH) the error disappears.