I am trying to write a little game in which there are bricks on a track.
My problem is that I would like to have a vector of bricks in the track class, but I would need to keep a pointer to the track in the brick class.
What I was trying to do is to have two header files track.h and brick.h and I wanted to include track.h in the brick.h file and vice-versa.
brick.h:
#pragma once
#include "track.h"
class brick
{
public:
brick (track &theTrack);
private:
track *mTrack;
};
brick::brick(track &theTrack)
{
mTrack = &theTrack;
}
track.h:
#pragma once
#include "brick.h"
class track
{
public:
private:
vector<brick> brickPositions;
};
However this results in compile errors.
I don’t use .cpp files for these classes, just a single .h file with #pragma once at the top.
Can you please explain what is the problem and how can I solve this?