Solution:
This is an interesting problem, because sometimes we have no choice but to declare an explicitly qualified name.
std::string convert();
namespace tools {
class Numeric {
// ...
// parsed as: "friend std::string::convert ();"
// (actual name is missing!).
friend std::string ::convert();
};
}
In that case, prepending the name with ::
is required, because otherwise we would declare and mark function tools::convert
as friend (in the enclosing namespace). A solution to this problem is to wrap parentheses around the name:
friend std::string (::convert)();
Challenge:
I have this code that fails to compile. Can you figure out what's wrong? It caused headache to me once.
// header
namespace values {
extern std::string address;
extern int port;
}
// .cpp file
std::string ::values::address = "192.0.0.1";
int ::values::port = 12;
It looks correct on the first sight. How many and which are the errors!?