C ++具有相同名称的多个类 [英] C++ Multiple classes with same name

查看:170
本文介绍了C ++具有相同名称的多个类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有两个不同的cpp文件。两者声明具有相同名称的类,但可能是完全不同的结构(或者可能是相同的结构,不同的实现)。这些类不会出现在头文件中。 (例如,假设它们是不同列表类的Node类。)



我看到这些类冲突。这是标准的预期吗?这个问题的标准方法是将这些类包装在不同的

http://www.cplusplus.com/doc/tutorial/namespaces/\">命名空间


Say I have two different cpp files. Both declare classes with the same name, but perhaps a totally different structure (or perhaps the same structure, different implementation). The classes do not appear in the header files. (As an example, suppose they are Node classes for different list classes.)

I've seen these classes conflict. Is this expected by the standard? What solutions are there to this problem?

解决方案

The standard way around this problem is to wrap the classes in different namespaces.

这篇关于C ++具有相同名称的多个类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆