C ++ / CLI C011类类型重定义 [英] C++/CLI C011 class type redefinition
本文介绍了C ++ / CLI C011类类型重定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Visual Studio Express 2013中,我有一个可执行的C ++ / CLI项目。它包含main.cpp,Class.h和Class.cpp文件。我收到错误C2011:N :: Class:class type redefinition。为什么以及如何修复它?
In Visual Studio Express 2013 I have an executable C++/CLI project. It contains main.cpp, Class.h and Class.cpp file. I'm getting "error C2011: N::Class : class type redefinition". Why and how to fix it?
//main.cpp
#include "stdafx.h"
#include "Class.h"
int main(array<System::String ^> ^args)
{
return 0;
}
// Class.h
#ifndef __Class_H__
#define Class_H__
namespace N {
public ref class C {
public:
Class();
};
}
#endif
// Class.cpp
#include "Class.h"
namespace N {
public ref class Class{
public:
Class() {
return;
}
};
}
推荐答案
在这里显示的代码片段中,您没有重新定义任何内容。此外,您没有类N :: Class
的定义,甚至没有显示它的声明。类类
是一个不同的类,Usb :: Class
,它不会创建任何名称冲突。也就是说,不显示两个类N :: Class
,而是显示零声明和零定义它。
所有在一起,涉及三个不同的类
:
In the code fragments you show here, you are not redefining anything. Moreover, you don't have the definition of the classN::Class
, not even a declaration of it is shown. The classClass
is a different class,Usb::Class
, it does not create any name clashes. That is, instead of showing two classesN::Class
you show zero declarations and zero definitions of it.
All together,three different classes
are involved:
-
N :: Class
(未在任何地方显示); -
N :: C
(仅声明)显示); -
Usb :: Class
(仅显示定义)。
N::Class
(not shown anywhere);N::C
(only declaration is shown);Usb::Class
(only definition is shown).
顺便说一句,将某个类命名为Class非常愚蠢。一些名称应用程序使用.EXE文件名称中的应用程序一词 - 同样的事情。像C这样的短名称也是不可接受的。在一些简单的实验中,当然,它可能并不重要。
很可能,你得到的错误信息包含不同的源代码,而不是你所显示的。无论如何,你的问题出在其他地方,在你没有向我们展示的代码中。
你真正的问题是不同的。这是提供足够信息的充分问题的能力。请注意这个问题。
这篇关于C ++ / CLI C011类类型重定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文