Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?

C++
//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


C++
// Class.cpp
#include "Class.h"

namespace N {
   public ref class Class{
      public:
         Class() {
            return;
         }
   };
}
Posted
Updated 9-Apr-14 10:52am
v3
Comments
Sergey Alexandrovich Kryukov 9-Apr-14 18:29pm    
gaminn wrote:
Sorry to waste your time. Please delete this topic.

[This message was posted as an answer and later auto-removed due to abuse reports — SA]

1 solution

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 (not shown anywhere);
  2. N::C (only declaration is shown);
  3. Usb::Class (only definition is shown).

By the way, naming some class as "Class" is pretty silly. Some name application using the word "application" in the name of .EXE file — same thing. Short names like "C" are also not acceptable. In some simple experiments, of course, it may be not important.

Chances are, you got your error message with different source code, not that you show. Anyway, your problem is somewhere else, in the code you did not show to us.

And your real problem is different. This is the ability to ask adequate questions supplying adequate information. Please pay attention for this problem.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900