HI,
i have small doubt related to the accessibility of variables.
int i; //default the linkage is external
const int i; //default linkage is i开发者_StackOverflow中文版nternal
extern int i; //explicitly assigning linkage as external
class a
{
int l; //Default linkage is external
void f()
{
int k; //default linkage is external
}
}
this link says default linkage is extern for non-const symbols and static (internal) for const symbols.
what about int i
is it accessible in other file with out having external keyword?
what about the variable present inside the class and functions?
How to aces the function present in anonymous name space & what linkage do they have?
namespace //members of anonymous namespace
{
class C{};
int x;
}
int i;
has external linkage, and is in a normal namespace, so it is accessible from other files. They will have to declare it extern int i;
in the same namespace (in this case, the global namespace) to access it.
Members of an unnamed namespace are not accessible from other files - that's the purpose of the namespace. Although they can have external linkage, their namespace is unique to the current file, so the same declarations in another file will refer to different things, unique to that file.
Refer here
Names in unnamed namespace have internal linkage.
精彩评论