如何处理重复的类名

编程入门 行业动态 更新时间:2024-10-26 19:36:35
本文介绍了如何处理重复的类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有点像c ++新手。我正在将一些静态库链接到 我的应用程序。事实证明,两个库(来自不同的 供应商)共享一个类名;例如他们都有一个名为 ''SomeClass''的班级。编译器/链接器正在抱怨。是否有一个简单的 方式处理这个,所以我的应用程序可以链接?谢谢。

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.

推荐答案

使用命名空间,这正是它们的用途。 use namespaces, this is exactly what they are for.

4MLA1FN写道: 4MLA1FN wrote: 我有点像c ++新手。我正在将一些静态库链接到我的应用程序中。事实证明,两个库(来自不同的供应商)共享一个类名;例如他们都有一个名为''SomeClass''的班级。编译器/链接器正在抱怨。是否有一个简单的方法处理这个,所以我的应用程序可以链接?谢谢。 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.

创建代理类。也就是说,实现所有相同的 方法作为您遇到问题的类之一,并且 只需将所有方法调用转发给实例它代表的是 的类。如果需要,请使用PIMPL习语(请参阅Google)。 - Alan Johnson

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

* 4MLA1FN: * 4MLA1FN: 我有点像c ++新手。我正在将一些静态库链接到我的应用程序中。事实证明,两个库(来自不同的供应商)共享一个类名;例如他们都有一个名为''SomeClass''的班级。编译器/链接器正在抱怨。是否有一个简单的方法处理这个,所以我的应用程序可以链接? 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?

不,据我所知,对不起。 但你可以在语言之外寻求解决方案。 例如,在Windows中你可以隔离其中一个类的使用 。动态链接的库。 或者,例如,你可以检查一些更高质量的库是否提供相同的功能 ,你应该这样做可能 无论如何都要做 - 使用低质量的库会产生越来越多的问题,并且可能会迫使你使用不太好的设计。 一个高质量的C ++库将使用命名空间来大大减少名称冲突的的机会,所以这是一件值得寻找的事情。 - 答:因为它弄乱了人们通常阅读文字的顺序。 问:为什么这么糟糕? A:热门发布。 问:什么是m在usenet和电子邮件中发生了令人烦恼的事情?

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?

更多推荐

如何处理重复的类名

本文发布于:2023-11-25 14:21:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630104.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何处理

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!