Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在visualstudioc++;?_C++_Visual Studio_Namespaces_Standards Compliance - Fatal编程技术网

C++ 如何在visualstudioc++;?

C++ 如何在visualstudioc++;?,c++,visual-studio,namespaces,standards-compliance,C++,Visual Studio,Namespaces,Standards Compliance,在VisualStudio2012中,我无法将某些名称声明为全局标识符,因为它们已经在math.h中声明。遗留问题使我不方便在源代码中重命名标识符。除了重命名,还有哪些选项 #include "stdafx.h" // iostream includes math.h which declares the following _CRT_NONSTDC_DEPRECATE(_y1) _CRTIMP double __cdecl y1(_In_ double _X); int y1; // er

在VisualStudio2012中,我无法将某些名称声明为全局标识符,因为它们已经在math.h中声明。遗留问题使我不方便在源代码中重命名标识符。除了重命名,还有哪些选项

#include "stdafx.h"
// iostream includes math.h which declares the following
_CRT_NONSTDC_DEPRECATE(_y1) _CRTIMP double  __cdecl y1(_In_ double _X);

int y1; // error - y1 is already declared

void Main()
{
    return;
}

奖金问题:VisualStudio 2012是否以一致的方式处理这个问题?

< P>因为这是C++,所以对于自己的东西,应该使用<强>命名空间< /强>,特别是如果你有全局变量时,

#include "stdafx.h"

namespace MyApp
{
    int y1; // MyApp::y1
}
通过这种方式,您可以使用using关键字,其中需要使用
y1
变量,而不使用名称空间名称:

using MyApp::y1; // Now also y1

标识符<代码> Y1 < /C> >可能出现在某些版本的>/CODE>中,但它不是由C或C++标准定义的。您应该能够通过禁用语言扩展,以避免声明

y1
的方式调用编译器。如果编译器不允许您这样做,那就是实现中的一个bug


y1()
是“第二类贝塞尔函数”之一(我不太清楚这是什么意思)。正如我在评论中所说,
iostream
将不包括
math.h
,而是
cmath
。微妙的区别在于
cmath
将所有内容都放在
std
名称空间中。问题是你做的事情如下

using namespace std;
不要。正如您所看到的,您自己在全局名称空间中引入了模糊性。相反,请尝试从
std
中显式指定所需内容,而不是用包含的头中声明的
std
成员污染全局命名空间。您还应该避免使用全局变量和全局名称空间本身


作为旁注,尝试显示整个代码,因为不清楚
\u tmain
是否在此处调用了
Main

您确定
iostream
包括
math.h
而不是
cmath
?确保您没有
使用命名空间std
。iostream最终会包含直接包含math的cmath。h.no,
cmath
保证在
std
命名空间中包含
math.h
。事实上,我是
使用命名空间std
。你促使我读书。我现在明白了,我是一个误入歧途的C程序员,没有为名称空间课程操心。现在更正。您要我发布一个答案让您接受吗?备注:您确定
void Main()
这里的签名正确吗?通常它是
int main
(MS的cl编译器可能期望
int\u tmain
)。
void main()
是一个完全有效的函数声明(假设链接器区分大小写)。这不是程序的入口点。如果打算将其作为入口点,那么至少有两件事是错误的。@KeithThompson我清楚地知道
void Main()
是有效的(…真的吗?),但不需要天才就能意识到他打算将其作为入口点。入口点确实是int\u tmain,它调用void Main。使用int_tmain会更规范。使用void Main会导致分心。抱歉。@oldrinb:事实证明,他并不打算将
void Main()
作为入口点。