如何处理Visual Studio C ++中的math.h污染? [英] How to deal with math.h pollution in Visual Studio C++?

查看:429
本文介绍了如何处理Visual Studio C ++中的math.h污染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In Visual Studio 2012, I'm unable to declare certain names as global identifiers because they're already declared in math.h. Legacy issues makes it inconvenient for me to rename the identifiers in the source code. What are the options besides renaming?

#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;
}

补充问题:Visual Studio 2012是否以一致的方式处理? p>

Bonus question: Is Visual Studio 2012 handling this in a conforming manner?

推荐答案

由于这是C ++,因此您应该使用命名空间

Since this is C++, you should use a namespace for your own stuff, especially if you have global variables.

#include "stdafx.h"

namespace MyApp
{
    int y1; // MyApp::y1
}

这样,你可以依靠使用关键字,您需要使用 y1 变量而不使用命名空间名称:

This way, you can rely on the using keyword, where you need to use your y1 variable without the namespace name:

using MyApp::y1; // Now also y1

这篇关于如何处理Visual Studio C ++中的math.h污染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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