C ++错误解决方案c2039不是全局命名空间的成员 [英] Solution for C++ error c2039 is not a member of global namespace

查看:673
本文介绍了C ++错误解决方案c2039不是全局命名空间的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


最近当我在VS 2010中编写c ++程序时,我开始收到错误

hi
Recently when I was writing c++ programs in VS 2010 I started getting the error
"

error c2039 is not a member of global namespace





为什么会发生这种情况?



我尝试了什么:



它被解决为我改变了我的#include指令的顺序。我的头文件已关闭,标准头文件上升。问题得到了解决。我很幸运能够在某个地方读过这个或者说,正在冥想帮助我。

" on separating the interface and implementation.

why would this happen?

What I have tried:

it was resolved as sooon as i changed the order of my # include directives. My header files went down and standard header files went up. the issue was resolved. I was lucky to have read this somewhere or may be, being meditative helped me.

推荐答案

在include部分中,标准头文件应该总是在写入的类文件之前程序员。
in the include section the standard header files should always precede the class files written by programmer.


常见的解决方案是在头文件的顶部包含那些系统和库头文件,这些文件是编译头文件所必需的,没有错误。



这意味着只包含头文件的include语句的源文件(可能包括 stdafx.h ;见下文)应该编译没有错误。



Visual Studio在这方面有点特别,因为在使用预编译的头文件时,许多Windows系统头文件通常包含在 stdafx.h 中。但是再次包含相同的文件并不会造成伤害(通过保护或使用 #pragma一次来跳过它们。)



在头文件中包含所有必需的头文件可确保它也可用于其他项目以及禁用预编译头时。虽然对于单个项目来说这可能不是必需的,但它是好的风格并允许重新用于其他项目。
The common solution is to include those system and library header files on top of your header files that are required to compile the header file without errors.

That means that a source file containing only an include statement for your header file (probably after including stdafx.h; see below) should compile without errors.

Visual Studio is a little bit special here because many of the Windows system header files are usually included with stdafx.h when using pre-compiled headers. But including the same files again does not harm (they are skipped by guarding or using #pragma once).

Including all necessary header files in your header file ensures that it can be also used for other projects and when pre-compiled headers are disabled. While this might be not not necessary for a single project, it is good style and allows re-using for other projects.


这篇关于C ++错误解决方案c2039不是全局命名空间的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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