English 中文(简体)
多重定义和名称空间
原标题:multiple definition and namespace

在名称空间行使职能,也就是在多个档案中加入这一正确方式吗?

测试。

#pragma once
    #ifndef TEST
    #define TEST
    namespace test{
    namespace {

        bool test(){
            return true;
        }
    }
}
#endif //TEST
最佳回答

包括警卫名称<代码>TEST可能与其他一些宏观因素发生冲突,使用更详细的内容,如<代码>。 HEADENAME_H。

注:先强调后加上门的名字和包含两条连续强调的名称保留执行。

其次,如果你在标题档案中重新提出,功能定义需要<条码>。 否则,如果列入多个翻译单位,就会出现多重定义链接错误。 或者更正式地说,标准规则(统一定义规则)禁止这种多重定义,除非它们重新插入所有<条码>、条码/编码,并且实际上相同。

www.un.org/spanish/ga/president

匿名名称空间使每个翻译单位都有一个单独的名称空间,每个此类名称空间都有一个单独的(相同)功能定义,而不是像上文标语中解释的那样,仅仅使用<条码>。

Cheers & hth.,

问题回答

Anonymous namespaces make all identifiers they wrap unique to the translation unit they are in. Putting an anonymous namespace into a header that will (sooner or later) be included in different translation units will result in all the identifiers defined in that anonymous namespace to be separately (but identically) in each translation unit.

我尚未看到有人想要这样做的情况。

是的。 因为它使你能够用同样的名字命名同样的物品,并且使这种名称简单。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签