• 13
• 16
• 27
• 9
• 9

# Two classes, same name - solution?

This topic is 1779 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,

after refactoring some of my old gui code by removing the "Gui" - prefixes and instead putting them into a gui-namespace, plus putting the file into a seperate folder, I've come across a problem. Now I've got some classes that share the same name, and also the same file-name:

// in "Gui/Window.h"
namespace gui
{
class Window {};
}

// in "Core/Window.h"
namespace core
{
class Window {};
}



Those two classes doesn't have anything in common. Before starting, I supposed this was safe, since both files are in different locations, and both classes are in different namespaces. However, when compiling the libary I get a compiler warning about multiple object-files with the same name, and upon compiling the actual game project, I get a lot of unresolved symbol linker errors.

Now I ask, is there any way to solve this, without adding some provisorical pre/postfix to the class?

Edited by Juliean

##### Share on other sites

There shouldn't be any linker errors. Are you sure it's caused by this? Did you refactor your .cpp files as well, not only headers?

##### Share on other sites
If both classes are still in separate namespaces then you can refer to them by prefixing them with the namespace:

Gui::Window
Core::Window

##### Share on other sites

Here you go. The errors I get are basically:

1>Debug\A.obj : warning LNK4042: Objekt mehrmals angegeben; zusätzliche Objekte werden ignoriert.
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall a::A::A(void)" (??0A@a@@QAE@XZ)" in Funktion "_main".
1>main.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: __thiscall a::A::~A(void)" (??1A@a@@QAE@XZ)" in Funktion "_main".
1>S:\Users\Juli\Documents\Visual Studio 2012\Projects\TestProject\Debug\TestProject.exe : fatal error LNK1120: 2 nicht aufgelöste Externe


Sorry for the german, I hope you get what it means. LNK4042: translates to "object referenced multiple times", and the other ones to "unsolved refernece to extern symbol".

I know how I can reference the classes, but this errors are just... weird, or am I missing something? Using visual studio 2012 ultimate, if that helps.

##### Share on other sites

This is indeed very weird. I got the same error bilding the project in MSVC++ Express 2012.

Renaming the files in B to B.h and B.cpp "fixed" it. Is this a compiler/linker bug?

##### Share on other sites

Please use a "normal" archiving format, like zip. Using something weird, like rar, will make people less likely to download the code.

Wait, rar a weird archiving format? In all due honesty, thats a new one for me, rar has been my "standard" for years now. But, never mind, I strongly suppose you know what you are talking about, so, yeah, will relate to zip in the future.

Anyway, thanks both of you for pointing that out. I wasn't able to find a feasable solution in the solution explorer - while I could change the obj output directory for a project, that doesn't work for a single class - I'll have no choice than renaming it. I might as well split the modules into seperate projects somewhere, but right now, the complexity doesn't justify that. Man, thats really a pain, I'd too like them to fix that...