I have a header and cpp file.I'm trying to learn OOP so I did a small program that handles classes.In the header I have declared the class and in the main file I'm implementing the methods.
m_prvi = first number
m_drugi = second number
m_rezultat = result
So I call newobject.Summate(5,3) and then newobject.print() and it does everything fine but why is not the constructor working properly?
It's a default constructor which should intiliaze the attributes (set their values to zero) but it doesn't.Why not?
EADER FILE
#ifndef _CLASS_H
#define _CLASS_H
class COseba
{
private:
int m_prvi;
int m_drugi;
int m_rezultat;
public:
void setNumber(int a, int b);
void Sestej();
void Izpisi();
COseba();
// ~COseba();
};
#endif
MAIN FILE
#include <iostream.h>
#include "class.h"
void COseba::setNumber(int a, int b)
{
m_prvi = a;
m_drugi = b;
}
void COseba::Sestej()
{
m_rezultat = m_prvi + m_drugi;
}
void COseba::Izpisi()
{
cout << "Rezultat je: " << m_rezultat << endl;
}
COseba::COseba()
{
m_prvi = 0;
m_drugi = 0;
m_rezultat = 0;
}
int main()
{
COseba novi;
novi.setNumber(5,3);
novi.Sestej();
novi.Izpisi();
COseba();//::COseba();
novi.Izpisi();
return 0;
}