Can't seem to get a simple stack implementation working. I'm simply trying to get two different classes (class B & class C) to be able to push and print element in the same stack being managed by a third class (class A).
A.cpp
#include "A.h"
void A::pop() {}
void A::push() {}
void A::print() {} // prints last pushed elements
A.h
#include < iostream >
class A
{
public:
void pop();
void push();
void print();
}
B.cpp
#include "B.h"
#include "A.h"
A a;
void B::Text() { a.push(); }
void B::Background() { a.print(); } // works!
C.cpp
#include "C.h"
#include "A.h"
A _a; // why doesn't A a work? because ODR?
void B::Text() { _a.push(); }
void B::Background() { _a.print(); } // doesn't work! breakpoint shows empty stack!
I think I'm breaking the One Definition Rule. Am I right?