首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

LINK2019解决办法

2012-04-04 
LINK2019#includeiostream#includestringusingnamespacestdtemplate classtypeclassString{private

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;
}
};

热点排行