For educational goals writing a class wrapper for sys/socket
.
https://github.com/nkt/cpp-socket/blob/master/src/Socket.cpp#L94 - this is method. https://github.com/nkt/cpp-socket/blob/master/chat/main.cpp#L17 - this is usage.
So, XCode throws an error:
Undefined symbols for architecture x86_64:
"Socket& operator<<<char const [16]>(Socket&, char const (&) [16])", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Although this code compiling and working fine:
#include <iostream>
#include <string>
class test
{
public:
void send(std::string str);
template <class T>
friend test &operator <<(test &tst, T &message);
};
void test::send(std::string str)
{
std::cout << str;
}
template <class T>
test &operator <<(test &tst, T &message)
{
tst.send(std::string(message));
return tst;
}
int main()
{
test t;
t << "hello world!\n";
}