本帖最后由 jiabiao113 于 2009-10-07 15:56:15 编辑

解决方案 »

  1.   

    模版的问题,直接在类里面定义吧,或者在h里面反过来include cpp,请看一下模版的两种实例化
      

  2.   

    模板函数定义不明确:template <class T>
    ostream& operator <<(ostream& out,const T& c)   
    {
    out << c.value;
    return out;
    }template <class T>
    class C1
    {
    friend ostream& operator << <C1<T>> (ostream&,const C1<T>&);
    public:
    C1(){value = 999;}
    private:
    int value;
    };
      

  3.   


    #include "iostream"
    using namespace std;template<class T>
    class C1
    {
    template<class U>
        friend ostream& operator<<(ostream&,const C1<U>&);
    public:
        C1(){value = 999;}
    private:
        int value;
    };//重载<<
    template<class T>
    ostream& operator<<(ostream& out,const C1<T>& c)    
    {
        out << c.value;
        return out;
    }int main()
    {
        C1<int> c;
        cout <<  c << endl;
        return 0;
    }
      

  4.   

    谢谢3楼 4楼的二位
    我看的教材就写错了,误导了我:
    template<class U>   //他把这部分没写
    friend ostream& operator<<(ostream&,const C1<U>&);