Ошибка в задании шаблона?

Рейтинг: 0Ответов: 5Опубликовано: 24.05.2011

При сборке возникает ошибка:

#include <iostream>
const int DefaultSize=10;
using namespace std;

template <class T>
class Array
{
  public:
    Array(int itsSize=DefaultSize);
    Array(const Array& rhs);
    ~Array() {delete [] pType;}

    Array& operator = (const Array&);
    T& operator[] (int offset){return pType[offset];}
    const T& operator [] (int offset) const {return pType[offset];}

    friend void Intrude(Array<int>);

    friend ostream& operator<< (ostream&, Array<T>&);  // < Компилятор указывает на 
    int GetSize() const {return itsSize;}              //эту строку

  private:
    T *pType;
    int itsSize;
};

template <class T>
ostream& operator << (ostream& output, Array<T>& theArray)
{
  for (int i=0;i<theArray.GetSize();i++)
    output<< "["<<i<<"]"<<theArray[i]<<endl;
  return output;
}

отчет во время компиляции:

g++ -Wall -c "template.cpp" (в каталоге: /host/projects/template) template.cpp:30:52: warning: friend declaration ‘std::ostream& >operator<<(std::ostream&, Array<t>&)’ declares a non-template function template.cpp:30:52: note: (if this is not what you intended, make sure the function >template has already been declared and add <> after the function name here) Сборка прошла успешно.

отчет при сборке:

g++ -Wall -o "template" "template.cpp" (в каталоге: /host/projects/template) template.cpp:30:52: warning: friend declaration ‘std::ostream& >operator<<(std::ostream&, Array<t>&)’ declares a non-template function template.cpp:30:52: note: (if this is not what you intended, make sure the function >template has already been declared and add <> after the function name here) /tmp/cciPebmn.o: In function main': template.cpp:(.text+0x162): undefined reference to >operator<<(std::basic_ostream<char, std::char_traits<char=""> >&, Array<int>&)' collect2: ld returned 1 exit status Сборка завершилась с ошибкой.

Ну и собственно вопрос: в чем ошибка?

Ответы

Ответов пока нет.