On 2018-01-16 14:45, Andrew Pinski wrote:
> On Mon, Jan 15, 2018 at 10:35 PM, chenzhelu <chenz...@netease.com> wrote:
>> Hello all,
>> I encountered a problem on "local class name conflict",
>> I searched on net and found that years ago, some people also encoutered this 
>> kind of problem.
>
> The correct name for this is One Definition Rule (or ODR for short).
> Basically a violation of this rule causes the code to be invalid (with
> no diagnostic required; therefor undefined code).  If you use LTO, GCC
> sometimes will warn about this violation.
>
> If you want a truly local class, then use anonymous namespaces which
> is designed to fix this issue.

After I tried the anonymous namespace, it really solve this!
namspace {
class LocalClassX {
     .....
};
}

In before, I took for granted that the default "empty namespace" is same with
"anonymous namespace", they are different.
C++ is really complex, I never use anonymouse namespace bofore.

Thanks a lot!

Reply via email to