I have an assignment for class and i received a header file and need to implement the methods of the class. I'm having trouble with implementing the copy constructor and overloading the = operator. Here is some of the header file:
class MontaznaKuca
{
private:
double kvadratura;
string bojaFasade;
string vlasnik;
bool postojiVrt;
Kuhinja* kuhinja;
vector<Soba*> sobe; //Soba is a seperate class defined in another header
public:
MontaznaKuca(void);
MontaznaKuca(double kvadratura, string bojaFasade, string imaVrt);
MontaznaKuca(const MontaznaKuca& kuca);
~MontaznaKuca(void);
MontaznaKuca& operator=(const MontaznaKuca& kuca);
...
My attempt ate the copy constructor and = operator overloading
MontaznaKuca::MontaznaKuca(const MontaznaKuca& kuca) : sobe(kuca.sobe.size())
{
kvadratura = kuca.kvadratura;
bojaFasade = kuca.bojaFasade;
vlasnik = kuca.vlasnik;
postojiVrt = kuca.postojiVrt;
kuhinja = new Kuhinja;
kuhinja = kuca.kuhinja;
for (size_t i = 0; i < kuca.sobe.size(); ++i)
sobe[i] = new Soba(*kuca.sobe[i]);
}
MontaznaKuca& MontaznaKuca::operator=(const MontaznaKuca& kuca) : sobe(kuca.sobe.size())
{
kvadratura = kuca.kvadratura;
bojaFasade = kuca.bojaFasade;
vlasnik = kuca.vlasnik;
postojiVrt = kuca.postojiVrt;
kuhinja = new Kuhinja;
kuhinja = kuca.kuhinja;
for (size_t i = 0; i < kuca.sobe.size(); ++i)
sobe[i] = new Soba(*kuca.sobe[i]);
return *this;
}
I did this by studying some code on the web and visual studio gives me an error
: constructor initializer lists are only allowed on constructor definitions
Can someone explain to me how to do these two functions, because i am completely lost.