0

Here is my code and declarations, im not sure how to properly set up friend functions with template classes. Can someone please guide me on what I did wrong and why?

Thanks!


private:
    int size;   
    T* buff; 
    friend Vector<T> operator * (const int n, const Vector<T> & v);

    friend Vector<T> operator + (const int n, const Vector<T> & v);


template<typename T>
Vector<T> operator * (const int n, const Vector<T> & v){
    Vector<T> vec(v.size);
    vec.size = v.size;
    for(int i = 0;i<vec.size;i++){
        vec.buff[i] = v.buff[i]*n;
    }
}
template<typename T> 
Vector<T> operator+ (const int n, const Vector<T> & v){
    Vector<T> vec(v.size);
    vec.size = v.size;
    for(int i = 0;i<vec.size;i++){
        vec.buff[i] = v.buff[i]*n;
    }
}

Drunkhydra
  • 47
  • 2
  • please add a minimal reproducible code – Oblivion Oct 20 '19 at 06:38
  • Undefined reference often means you've run afoul of [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file)Give it a read over and if that answers your question, we'll close as a duplicate. If not, [mcve], please. – user4581301 Oct 20 '19 at 06:48

0 Answers0