My getter function keeps returning the same constant value, despite it changing over time.
Main
#include <iostream>
#include "Moo.h"
using std::cout;
using std::endl;
int main()
{
bool running = true;
Foo foo;
Moo moo;
while(running)
{
foo.Update(); <-- m_r is updated
moo.Show(); <--- m_r remains zero
}
system("Pause");
return 0;
}
Foo.h
#ifndef FOO_H_
#define FOO_H_
class Foo
{
public:
int getR();
void Update();
Foo();
private:
int m_r;
};
#endif
Foo.cpp
#include "Foo.h"
Foo::Foo()
{
m_r = 0;
}
int Foo::getR()
{
return m_r;
}
void Foo::Update()
{
m_r++;
}
Moo.h
#ifndef MOO_H_
#define MOO_H_
#include "Foo.h"
class Moo
{
public:
void Show();
private:
Foo foo;
};
#endif
Moo.cpp
#include <iostream>
#include "Moo.h"
using std::cout;
using std::endl;
void Moo::Show()
{
cout << foo.getR() << endl; //<-- The following returns zero, despite being updated in Foo Update
}
Why isn't the getter function updating, what am I missing? Thanks in advance