i have a function declared in a namespace, that when it is defined as a friend, throws a compiler error.
#include <string>
#include <vector>
namespace Example
{
std::vector<std::string> GetNames();
}
class MyClass
{
public:
MyClass() :
name("data")
{}
private:
std::string name;
friend std::vector<std::string> ::Example::GetNames();
};
this fails to compile with the error
'Example' in 'class std::vectorstd::__cxx11::basic_string<char >' does not name a type friend std::vectorstd::string ::Example::GetNames(); ^~~~~~~ main.cpp:25:2: error: expected ';' after class definition
yet if i remove the global namespace identifier, ::
from ::Example::GetNames()
, it will compile happily.
how do i deal with this issue when i need to start at the global namespace due to nested namespaces?