-1

Here is my code

#include <iostream>
using namespace std;
#include "mykouti.h"

int main()
{
    Kouti koutiA(2.0, 3.2, 6.0);
    Kouti koutiB(2.5, 4.0, 5.0);
    Kouti koutiC;

    // Display the volume of each box
    cout << "KoutiA volume is: " << koutiA.calculateOgkos()
        << "\nKoutiB volume is: " << koutiB.calculateOgkos()
        << endl;

    koutiC = koutiA + koutiB;

    cout << "KoutiC volume is: " << koutiC.calculateOgkos() << endl;

    return 0;
}

// mykouti.cpp
#include <iostream>
#include "mykouti.h"

//constructor that initialize Box dimensions
Kouti::Kouti(double length, double breadth,
              double height)
{
    setDimensions(length, breadth, height);
}

void Kouti::setDimensions(double mikos, double platos, double ypsos)
{
    setMikos(mikos);
    setPlatos(platos);
    setYpsos(ypsos);
}

void setMikos(double mikos)
{
   length = mikos;
}

void setPlatos(double platos)
{
   breadth = platos;
}

void setYpsos(double ypsos)
{
   height = ypsos;
}

double Kouti::calculateOgkos() const
{
    return length*breadth*height;
}

Kouti::Kouti operator+(const Kouti& b)
{
    Kouti kouti;
    kouti.length = this->length + b.length;
    kouti.breadth = this->breadth + b.breadth;
    kouti.height = this->height + b.height;
    return kouti;
}

// mykouti.h -- Box class before operator overloading
#ifndef MYKOUTI_H_
#define MYKOUTI_H_

class Kouti
{
    public:
        //constructor that initialize Box dimensions
        explicit Kouti(double = 0.0, double = 0.0, double = 0.0);
        void setDimensions(double, double, double);
        void setMikos(double);        //setlength()
        void setPlatos(double);      //setwidth()
        void setYpsos(double);        //setheigth()
        double calculateOgkos() const;
        Kouti operator+(const Kouti& b);

    private:
        double length;
        double breadth;
        double height;
};
#endif // MYKOUTI_H_

I tried to separate the code in 3 files. working from deitel book C++ 9th edition and Stephen prata C++ Primer Plus.
When I compile code I get these errors:

Errors

Can you help me solve this? thanks

awesoon
  • 32,469
  • 11
  • 74
  • 99

1 Answers1

1

You need to qualify your member function definitions with Kouti::

void Kouti::setMikos(double mikos)
     ^^^^^^^
void Kouti::setPlatos(double platos)
     ^^^^^^^    
void Kouti::setYpsos(double ypsos)
     ^^^^^^^

also your operator+ definition should look like this:

Kouti Kouti::operator+(const Kouti& b)
marcinj
  • 48,511
  • 9
  • 79
  • 100
  • *"also your operator+ definition should look like"*, or even `Kouti Kouti::operator+(const Kouti& b) const` – Piotr Skotnicki May 10 '16 at 12:09
  • I have found the problem. Besides the qualification of the member functions and the correction of the operator+ definition I had to add the Kouti.h file and Kouti.cpp files to the project pane on the left of code blocks. (I had changed the names of mykouti.h and mykouti.cpp to Kouti.h and Kouti.cpp). Now code runs as expected. How do I mark my answer as the answer to this question? – Alexandros81 May 10 '16 at 12:32