I am not able to overload the + operator and I have no idea why. I've tried a lot of solutions but I didn't manage to solve this problem. (Operator += works fine)
I don't get it. Could you help?
I get error:
LNK2019: unresolved external symbol "public: __thiscall Zbior::Zbior(class Zbior const &)" (??0?$Zbior@H@@QAE@ABV0@@Z) referenced in function "public: class Zbior __thiscall Zbior::operator+(class Zbior const &)" (??H?$Zbior@H@@QAE?AV0@ABV0@@Z)
The problem does not exist when I change the return object of method: Zbior operator+ (const Zbior &other)
to
return Zbior<T>();
My .h file is:
template<class T>
class Zbior
{
public:
    Zbior(void);
    ~Zbior(void);
    void dodajElement(T elem);
    Zbior<T>(vector<T> elementyZbioru);
    Zbior<T>(Zbior<T> const &other);     
    Zbior<T>& operator+=(Zbior<T> const &other);
    Zbior<T>  operator+ (const Zbior<T> &other)
    {
        vector<T> otherVec = other.elementyZbioru;
        vector<T> thisVec = elementyZbioru;
        Zbior<T> wyjZbior = Zbior<T>();
        for (vector<T>::iterator p = otherVec.begin(); p != otherVec.end(); ++p)
        {
            wyjZbior.dodajElement(*p);
        }
        for (vector<T>::iterator p = thisVec.begin(); p != thisVec.end(); ++p)
        {
            wyjZbior.dodajElement(*p);
        }
        return Zbior<T>(wyjZbior);
    }
private:
    vector<T> elementyZbioru;
};
And my .cpp file is:
#include "Zbior.h"
template<class T>
Zbior<T>::Zbior(void)
{
}
template<class T>
Zbior<T>::~Zbior(void)
{
}
template<class T>
Zbior<T>::Zbior(vector<T> elementyZbioru)
{
    this->elementyZbioru = elementyZbioru;
}
template<class T>
void Zbior<T>::dodajElement(T  elem){
    this->elementyZbioru.push_back(elem);
}
template<class T>
Zbior<T>& Zbior<T>::operator+=(Zbior<T> const &inny){
    vector<T> innyElementyZbioru = (inny.elementyZbioru);
    for (vector<T>::iterator p = innyElementyZbioru.begin(); p != innyElementyZbioru.end(); ++p)
    {
        dodajElement(*p);
    }
    return *this;
}
Ussage of the class:
#include "stdafx.h"
#include "Zbior.cpp"
#include "Zbior.h"
int _tmain(int argc, _TCHAR* argv[])
{
    Zbior<int> zb1 = Zbior < int>();
    zb1.dodajElement(1);
    zb1.dodajElement(1312);
    Zbior<int> zb2 = Zbior < int>();
    zb2.dodajElement(21);
    zb2.dodajElement(21312);
    //zb1 += zb2;
    Zbior<int> zb = zb1 + zb2;
    //Zbior<Zbior<int>> zbzb = Zbior<Zbior<int>> ();
    //zbzb.dodajElement(zb1);
    //zbzb.dodajElement(zb2);
    system("PAUSE");
    return 0;
}
 
     
     
    