473,563 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to deal with duplicate class names

i'm somewhat of a c++ newbie. i'm linking some static libraries into
my app. it turns out that two of the libraries (from different
suppliers) share a class name; e.g. they both have a class named
'SomeClass'. the compiler/linker is complaining. is there an easy
way deal with this so my app can link? thanks.
May 8 '06 #1
10 3475
use namespaces, this is exactly what they are for.

May 8 '06 #2
4MLA1FN wrote:
i'm somewhat of a c++ newbie. i'm linking some static libraries into
my app. it turns out that two of the libraries (from different
suppliers) share a class name; e.g. they both have a class named
'SomeClass'. the compiler/linker is complaining. is there an easy
way deal with this so my app can link? thanks.


Create proxy class. That is, one that implements all of the same
methods as one of the classes with which you are having problems, and
have it simply forward all method calls to an instance of the class for
which it is proxying. If needed, use the PIMPL idiom (see Google).

--
Alan Johnson
May 8 '06 #3
* 4MLA1FN:
i'm somewhat of a c++ newbie. i'm linking some static libraries into
my app. it turns out that two of the libraries (from different
suppliers) share a class name; e.g. they both have a class named
'SomeClass'. the compiler/linker is complaining. is there an easy
way deal with this so my app can link?


No, not as far as I know, sorry.

But you can pursue solutions outside the language.

For example, in Windows you can isolate the usage of one of the classes
to a dynamically linked library.

Or, for example, you can check whether the same functionality is
available from some higher quality libraries, which you should probably
do anyway -- using low-quality libraries will yield more and more
problems, and can force you to use less than good design.

A quality C++ library will use a namespace to greatly reduce the chance
of name collisions, so that's one thing to look for.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 8 '06 #4

Alan Johnson wrote:
4MLA1FN wrote:
i'm somewhat of a c++ newbie. i'm linking some static libraries into
my app. it turns out that two of the libraries (from different
suppliers) share a class name; e.g. they both have a class named
'SomeClass'. the compiler/linker is complaining. is there an easy
way deal with this so my app can link? thanks.


Create proxy class. That is, one that implements all of the same
methods as one of the classes with which you are having problems, and
have it simply forward all method calls to an instance of the class for
which it is proxying. If needed, use the PIMPL idiom (see Google).


This does not solve the problem. The problem is that One Definition
Rule is violated and you have several different external linkage
entities with the same name in your application. Adding a proxy to the
mix does not make the entity being proxied go away.

May 8 '06 #5
Maxim Yegorushkin wrote:

Alan Johnson wrote:
4MLA1FN wrote:
> i'm somewhat of a c++ newbie. i'm linking some static libraries into
> my app. it turns out that two of the libraries (from different
> suppliers) share a class name; e.g. they both have a class named
> 'SomeClass'. the compiler/linker is complaining. is there an easy
> way deal with this so my app can link? thanks.


Create proxy class. That is, one that implements all of the same
methods as one of the classes with which you are having problems, and
have it simply forward all method calls to an instance of the class for
which it is proxying. If needed, use the PIMPL idiom (see Google).


This does not solve the problem. The problem is that One Definition
Rule is violated and you have several different external linkage
entities with the same name in your application. Adding a proxy to the
mix does not make the entity being proxied go away.


Well, with standard C++, you're right. But the linker might offer some way
to only export symbols that are explicitly marked for that (e.g. in a
linker script). That can be used to make only the proxy class visible for
the main program.

May 8 '06 #6
yu*****@gmail.c om wrote:
use namespaces, this is exactly what they are for.


I think the OP doesn't have that choice. Read the post again and you'll
find it is the library code (not OP's code) that caused the problem.

Putting library code in your own namespace is not only a substantial
work but is also unsupported, tedious, and error-prone.

Regards,
Ben
May 8 '06 #7

Rolf Magnus wrote:
Maxim Yegorushkin wrote:

Alan Johnson wrote:
4MLA1FN wrote:
> i'm somewhat of a c++ newbie. i'm linking some static libraries into
> my app. it turns out that two of the libraries (from different
> suppliers) share a class name; e.g. they both have a class named
> 'SomeClass'. the compiler/linker is complaining. is there an easy
> way deal with this so my app can link? thanks.

Create proxy class. That is, one that implements all of the same
methods as one of the classes with which you are having problems, and
have it simply forward all method calls to an instance of the class for
which it is proxying. If needed, use the PIMPL idiom (see Google).


This does not solve the problem. The problem is that One Definition
Rule is violated and you have several different external linkage
entities with the same name in your application. Adding a proxy to the
mix does not make the entity being proxied go away.


Well, with standard C++, you're right. But the linker might offer some way
to only export symbols that are explicitly marked for that (e.g. in a
linker script). That can be used to make only the proxy class visible for
the main program.


In standard C++ one had best be using namespaces to solve the problem.

May 8 '06 #8
Maxim Yegorushkin wrote:
>> Create proxy class. That is, one that implements all of the same
>> methods as one of the classes with which you are having problems, and
>> have it simply forward all method calls to an instance of the class
>> for which it is proxying. If needed, use the PIMPL idiom (see
>> Google).
>
> This does not solve the problem. The problem is that One Definition
> Rule is violated and you have several different external linkage
> entities with the same name in your application. Adding a proxy to the
> mix does not make the entity being proxied go away.


Well, with standard C++, you're right. But the linker might offer some
way to only export symbols that are explicitly marked for that (e.g. in a
linker script). That can be used to make only the proxy class visible for
the main program.


In standard C++ one had best be using namespaces to solve the problem.


With "one" in this case being those that wrote the libraries that the OP is
using. Noting that namespaces are there to avoid that problem won't help
the OP solving it.

May 8 '06 #9
4MLA1FN posted:
i'm somewhat of a c++ newbie. i'm linking some static libraries into
my app. it turns out that two of the libraries (from different
suppliers) share a class name; e.g. they both have a class named
'SomeClass'. the compiler/linker is complaining. is there an easy
way deal with this so my app can link? thanks.

Maybe you could find some tool for altering the static library file? (Even
a text editor?). If you find such a tool, the handiest solution would be:

1) Put everything in a namespace.
Failing that, you could:

2) Rename the classes.
You'd probably need a fancy tool to achieve the first choice, but I'd say
that something as trivial as a HexEditor could achieve the second choice.
-Tomás
May 8 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2323
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten it. Perhaps there are some python features or libraries I'm not taking advantage of. The way it works is that it puts references to all the files...
44
4007
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are identical with which. Write a program that prints out which file are redundant copies. Here's the spec. -------------------------- The program is...
7
23909
by: Voetleuce en fênsievry | last post by:
Hello everyone. I'm not a JavaScript author myself, but I'm looking for a method to remove duplicate words from a piece of text. This text would presumably be pasted into a text box. I have, for example, a list of town names, but there are hundreds of duplicates, like: "Aberdeen Aberdeen Aberdeen Edinburg Edinburg Inverness etc."
3
13821
by: shine | last post by:
I am trying to add an integer array to a hashtable. While adding to hashtable I want to check the duplicates in array, the way I want to do is add the key(the integer stored in array) if a duplicate key is being added then the program should return the integer else it should return -1. Here is the piece of code I have written does the logic...
23
2676
by: Steve Jorgensen | last post by:
Hi all, I'm working on a project through a consulting company, and I'm writing some database code for use in another programmer's project in Excel/VBA. The other programmer is working through the same consulting company. I did not initially know this other programmer's experience level, but he seemed down to earth and friendly. I saw...
8
3917
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on this line: Set rs = db.OpenRecordset("SELECT ID FROM Contacts WHERE (" & sWhere & ");") Contacts being the main table. I am using access 2003...
4
3400
by: whatnameisnottaken | last post by:
right now i have gotten all the classes to print out using helpdbg. Now i want to remove the duplicate class names out of an array so i can just print one of each. This is the output i have. class URopeBeamEmitter; class AAGP_GameInfo; class AAGP_Weapon; class ABaseScope; class AInfantryHUD; class UCamEffect_BlurOut; class...
4
1600
by: | last post by:
Given an XML file (dataset.writexml), here is my output (simplified for this posting): <?xml version="1.0" standalone="yes"?> <NewDataSet> <Category> <CategoryId>80</CategoryId> <Category>MyCat</Category> </Category> </NewDataSet>
5
1842
by: Brett Barry: Go Get Geek! | last post by:
Hello, Can someone please paste VBA code and how I would go about doing this?: I have a customer table with over 6000 duplicates in the field called "Customer". While the customer names may be duplicates the data in other fields is different. I would like to import all of the customers including the duplicates; however, the program I am...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.