I believe I am having a circular dependency problem. I researched other answers but I do not understand how to use the forward declaration to fix my problem.
I have the following composition:
+------------------+
|Session <---------------+
| | |
| +------------+ | Must know
| |Dataset | | about
| | | | ^
| | | | |
| | +---------+
| | | |
| | | |
| +------------+ |
| |
+------------------+
From the code posted below, can you spot any circular dependencies or problems? I can post more code if necessary. It's a complex system and I'm trying to boil the issue down to it's most basic part.
Session.h
#include "Dataset.h"
...
namespace bmd2 {
class Session {
private:
std::vector<std::shared_ptr<bmd2::Dataset>>
datasetContainer; // error here
Dataset.h
#include "Session.h" // when I include this line I get strange errors
namespace bmd2 {
class Dataset {
private:
bmd::Session & session;
Some of the errors I get when I make Dataset aware of Session is:
Session.h Dataset in namespace bmd2 does not name a type
First try
So I tried this:
Dataset.h
// removed include
namespace bmd2 {
class Dataset {
class Session;
private:
bmd2::Session & session;
Dataset.cpp
#include "Session.h"
bmd2::Dataset::Dataset(bmd2::Session & _session,
bmd2::Logger & _logger,
const std::string & filePath,
bmd2::File::FileMode fileMode)
: session(_session), logger(_logger)
{
and I still get: 'Session" in namespace bmd2 does not name a type. This is so frustrating.