Click here to Skip to main content
15,868,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
When I am adding header file from existing project to new ActiveX Control dll project, getting below error :

error C2011: 'ProfileSettings' : 'class' type redefinition.

Strange thing is that, same header file included into another projects as well, for which during build not getting such errors.

What I have tried:

I looked as possible solutions from google, many answers are include header guard, but same file included into old projects as well, in which not getting such error. Can you please help me? Is there any project configuration which I am missing?

Thanks in advance
Posted
Updated 23-Sep-19 21:49pm
Comments
KarstenK 24-Sep-19 2:13am    
Renameyour class is the easiest solution.

Could be a name clash. Try to change the name of the class or, better, enclose it in a namespace.
By the way, the compiler message should indicate where it was already defined.
 
Share this answer
 
v2
Comments
Member 14373667 23-Sep-19 9:30am    
I checked all the things related class, but i am confused, because same file is included into existing projects where not getting error during build. And in new project name of classes defined with different names, so not issue with clashing class name due to new project, I could not share codes as it is corporate project.
We annot help without proper detailed information. You need to check the line where the error occurs to and search other files for the duplicate. Visual Studio can search your entire project for references.
 
Share this answer
 
Here's an experiment you can try. Instead of the standard include file guard which looks like this:
C++
// HeaderFile.h

#ifndef HEADERFILE_H
#define HEADERFILE_H

// ... code goes here

#endif // HEADERFILE_H
change it to generate an error if it is repeatedly included so you can track down the problem. That would look like this:
C++
// HeaderFile.h - revised to generate an error on repeated inclusion

#ifndef HEADERFILE_H
#define HEADERFILE_H
#else
#error this file was repeatedly included
#endif

/***
#ifndef HEADERFILE_H     // this is here so it can be easily copy and pasted
#include "HeaderFile.h"  // and the file can be safely included when needed
#endif                 
 ***/

// ... code goes here
This macro definition will cause an error if you include it repeatedly but you can use the ifdef that is commented and always do it safely. Try this and see if it points out where your problem is.

I do this in all my include files because it can greatly increase compilation speeds on large projects. I also make all header files self-contained, meaning they include everything they need to compile correctly, and this habit helps a lot.

FWIW, I got this idea from Microsoft. They used to do this often in the Win32 SDK headers but not so much any more since pragma once effectively does the same thing. I prefer to get an error so I can track down problems easier.
 
Share this answer
 
Hello All,

Thank you for your help, I understood issue.

In new project, there was reference of one existing project. Referenced project also included file with "ProfileSettings" Class.

After setting below Property to false, able to build successfully :

Common Properties --> References --> (click on referenced project) --> Reference Assembly Output --> Set to FALSE
 
Share this answer
 

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