cygwin + 友元 + 模板特化?顺便散分
#include <string>
#include <iostream>
namespace space
{
template <class T>
void show(const T&);
};
class myclass
{
public:
myclass() : name("myname") {}
private:
std::string name;
friend void space::show<myclass>(const myclass&);
};
namespace space
{
template<>
void show<myclass>(const myclass& obj)
{
std::cout << obj.name << std::endl;
}
}
int main()
{
myclass a;
space::show(a);
return 0;
}
Linux下gcc 4.1.1编译通过,但cygwin下gcc 3.4.4就不行,报错:
error : 'void space::show(const myclass &)' should have been declared inside 'space'
请大家给出一个cygwin下能通过的修改方案