LINK2019
#include <iostream>
#include <string>
using namespace std;
template <class type> class String {
private:
type data;
typename type::iterator it;
public:
String(){}
explicit String(type a):data(a){ it = data.begin(); }
void print() { cout < < *it < < endl; }
friend ostream& operator < <(ostream& os, const String <type> & ob);
};
template <class type>
ostream& operator < <(ostream& os, const String <type> & ob) {
cout < < ob.data;
return os;
}
int main( void ) {
String <string> ob( "asfdsaf ");
cout < < ob < < endl;
return 0;
}
帮忙看一下上面的代码连接错误是怎么回事?
[解决办法]
template <typename type> class String {
private:
type data;
typename type::iterator it;
public:
String(){}
explicit String(type a):data(a){ it = data.begin(); }
void print() { cout < < *it < < endl; }
friend ostream& operator < <(ostream& os, const String <type> & ob)
{
cout < < ob.data;
return os;
}
};