C ++ / CLI C011类类型重定义 [英] C++/CLI C011 class type redefinition

查看:110
本文介绍了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 class N::Class, not even a declaration of it is shown. The class Class is a different class, Usb::Class, it does not create any name clashes. That is, instead of showing two classes N::Class you show zero declarations and zero definitions of it.

All together, three different classes are involved:
  1. N :: Class (未在任何地方显示);
  2. N :: C (仅声明)显示);
  3. Usb :: Class (仅显示定义)。
  1. N::Class (not shown anywhere);
  2. N::C (only declaration is shown);
  3. Usb::Class (only definition is shown).



顺便说一句,将某个类命名为Class非常愚蠢。一些名称应用程序使用.EXE文件名称中的应用程序一词 - 同样的事情。像C这样的短名称也是不可接受的。在一些简单的实验中,当然,它可能并不重要。



很可能,你得到的错误信息包含不同的源代码,而不是你所显示的。无论如何,你的问题出在其他地方,在你没有向我们展示的代码中。



你真正的问题是不同的。这是提供足够信息的充分问题的能力。请注意这个问题。



-SA


这篇关于C ++ / CLI C011类类型重定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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