I'm having a circular dependency problem. Basically I have two classes, the first is a template class which uses some functionality from my second class. The second class inherits from my template class.
Below is a simplified structure:
// Foo.h
#pragma once
#include "Bar.h"
template <class T> class Foo
{
public:
void DoSomething();
};
template <class T> void Foo<T>::DoSomething()
{
Bar::GetInstance()->LogEvent();
}
//Bar.h
#pragma once
#include "Foo.h"
class Bar : public Foo<Bar>
{
public:
static Bar* GetInstance();
void LogEvent();
};
//Bar.cpp
#include "Bar.h"
Bar* Bar::GetInstance()
{
// return instance of Bar singleton class
}
void Bar::LogEvent()
{
// log some event in a file
}
Now the problem is when I complile the code I am getting the following errors in bar.h
Bar.h() : error C2504: 'Foo' : base class undefined
Bar.h() : error C2143: syntax error : missing ',' before '<'
From what I can tell this a definitely a dependency problem. If I remove the call to 'LogEvent' from within 'DoSomething', and remove reference "Bar.h" from Foo.h the issue goes away.
However it's not really a solution because Foo needs functionality contained with Bar, conversely bar inherits from Foo and needs to include a reference to Foo.h.
So - how can I resolve this problem? I have looked through the other posts regarding circular references but I haven't been able to solve the problem.
Thanks
;
at the end of your class definitions. – MankarseT::GetInstance()
work for your needs ? (at least the way you have it right now)? – WhozCraig