Static data member of a class is Internal Linkage or External?
Asked Answered
C

2

6

Static data member in a class(in C++) will be considered as internal linkage or external linkage ? I did google but couldn't find out anything concrete for static member variables.

Cajolery answered 18/7, 2014 at 14:12 Comment(0)
A
9

They have external linkage. See http://msdn.microsoft.com/en-us/library/zbh4586z.aspx (thanks Raymond !).

Ainsworth answered 18/7, 2014 at 14:22 Comment(3)
Damn, I thought the class static members has the same static linkage as other static declared non-class variables. Very misleading..Colpotomy
@Colpotomy nope! static has several different meanings depending on context... That's the committee being stingy with keywords :)Ainsworth
Microsoft documentation is not authoritative, and in this case, wrong.Chief
I
1

I was also interested in this question recently, and I found this in N4659 (Some draft of C++17):

§ 6.5.5 In addition, a member function, static data member, a named class or enumeration of class scope, or an unnamed class or enumeration defined in a class-scope typedef declaration such that the class or enumeration has the typedef name for linkage purposes (10.1.3), has the same linkage, if any, as the name of the class of which it is a member.

So static data member can have internal or external linkage, decided by the class itself. For example, static data member of a class in unnamed namespace should have internal linkage.

In answered 27/2, 2023 at 8:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.