【发布时间】:2023-08-11 07:03:01
【问题描述】:
考虑以下代码:
#include <stdio.h>
namespace EnclosingNmspc
{
namespace Nmspc
{
extern int a;//This a and the a defined above denote the same entity
int a=5;
}
}
extern int a;
int main()
{
printf("%d\n",a);
}
有3.5/2的报价:
当一个名字有外部链接时,它表示的实体可以是 由来自其他翻译单元范围的名称或来自 同一翻译单元的其他范围。
我不明白为什么这条规则在我的情况下不起作用?我有undefined reference 链接器错误。
【问题讨论】: