[英]What happens when there are two functions with the same signature in the same namespace?
As far as I understand, I can use namespaces to avoid functions overriding each other.据我所知,我可以使用命名空间来避免函数相互覆盖。 But what if the namespaces have the same names?
但是如果命名空间具有相同的名称呢?
I included both of the .h files below, called VideoLibrary::check() and it compiles.我包括了下面的两个 .h 文件,称为 VideoLibrary::check() 并编译。 Why?
为什么? Doesn't it contradict the purpose of namespace?
这不是与命名空间的目的相矛盾吗?
file1.h and file2.h: file1.h 和 file2.h:
namespace VideoLibrary
{
void check();
}
file1.cpp:文件1.cpp:
namespace VideoLibrary
{
void check()
{
printf("check1");
}
}
file2.cpp:文件2.cpp:
namespace VideoLibrary
{
void check()
{
printf("check2");
}
}
I'm concerned mostly because my project includes external libraries, and i'm worrying it includes functions with the same signature as in my project.我担心主要是因为我的项目包含外部库,我担心它包含与我的项目具有相同签名的函数。 How can I get any error for such a case in compilation time?
我怎样才能在编译时得到这种情况的任何错误? I'm using Xcode as an editor if it matters.
如果重要的话,我将 Xcode 用作编辑器。
如果您在不同的翻译单元中有 2 个(非内联)相同函数的定义,则您有 ODR(一个定义规则)违反 NDR(无诊断要求)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.