问题
When reading articles, manuals, etc... about programming, i always come across the word qualified
. like in java the fully qualified class name would be com.example.Class. Reading
this article, defines the scope resolution operator ::
in C++ as being used to Qualify hidden names so you can still use them. Is there a definition for this ? Beccause it seems to be used in a different context each time.
回答1:
In computer programming, a fully qualified name is an unambiguous name that specifies which object, function, or variable a call refers to without regard to the context of the call. In a hierarchical structure, a name is fully qualified when it "is complete in the sense that it includes (a) all names in the hierarchic sequence above the given element and (b) the name of the given element itself." Thus fully qualified names explicitly refer to namespaces that would otherwise be implicit because of the scope of the call. While always done to eliminate ambiguity, this can mean different things dependent on context.
Source Wikipedia
In short what it means is that,
You can have a class named Math
in your project, but Math
is already present in Java too.
So for unambiguously identifying which class you are actually referring to you need to qualify the name with package too:
java.lang.Math //refers to java class Math
org.myproject.Math //refers to your project Math class
回答2:
From Merriam Webster
Full Definition of QUALIFY
transitive verb 1 a : to reduce from a general to a particular or restricted form : modify b : to make less harsh or strict : moderate c : to alter the strength or flavor of d : to limit or modify the meaning of (as a noun) 2 : to characterize by naming an attribute : describe 3 a : to fit by training, skill, or ability for a special purpose b (1) : to declare competent or adequate : certify (2) : to invest with legal capacity : license
Clauses 1 and 2 apply. Java and C++ both have scoping/namespaces, and "qualify" means to introduce sufficient scopes to distinguish between potential candidates.
C.f.: If you have two classes with a member called "read".
class Foo {
void read();
};
class Bar {
void read();
};
In your implementation file, you will implement both functions. But if you wrote (C++)
void read() {}
This is valid, but it creates a function in the global namespace, rather than implementing one of the two functions. The same code written inside the class Foo definition would implement Foo::read.
So to implement our member functions outside the class definitions, we have to qualify - to reduce from general, to name the attribute of the container path - which read we are implementing.
void Foo::read() {}
void Bar::read() {}
The global namespace is "::", so you can even be explicit if you are trying to use that:
void ::read() {} // note: this name is already taken by stdio's read() :)
来源:https://stackoverflow.com/questions/18803036/what-does-qualify-mean