Reputation: 2399
I have read this and it says that
names of classes, their member functions, static data members (const or not), nested classes and enumerations, and functions first introduced with friend declarations inside class bodies
have external linkage by default.. But what about the variables declared inside the class body that are not specified static? Also, it starts out with
Any of the following names declared at namespace scope have external linkage
, but is class scope considered a namespace scope? I mean class scope and namespace scope are different, so why do they start out by saying that the following is applicable for the mentioned declared inside a namespace scope? I mean, for example, member functions are declared in class scope and they mention them as if it was namespace scope?
Upvotes: 4
Views: 871
Reputation: 119877
Quote from the standard:
A name is said to have linkage when it might denote the same object, reference, function, type, template, namespace or value as a name introduced by a declaration in another scope
Translation to plain English:
If you can redeclare it in another scope, it has linkage. Otherwise, nope.
You cannot redeclare a non-static class data member in another scope, so it has no linkage.
Upvotes: -1
Reputation: 25526
Following example:
class C
{
public:
int n;
};
C e;
namespace { C i; }
e
has external linkage, i
internal. How much sense would it make to speak of linkage of n
now? If at all, you could consider n
inheriting the linkage of the containing object, thus e.n
would have external, i.n
internal linkage – for better understanding only, I do not consider this as correct wording...
Upvotes: 2