Я пытался передать класс Graphics Manager как классу Robot, так и классу Room.
Но при попытке передать класс по ссылке я получаю 3 ошибки относительно передачи по ссылке.
Это ошибки, на которые я ссылаюсь: синтаксическая ошибка C2143: отсутствует ';'до '*'
C4430 отсутствует указатель типа - предполагается int.Примечание: C ++ не поддерживает default-int
C2238 неожиданный токен (ы), предшествующий ';'
Я пытался изменить способ прохождения классов, но безуспешно,Я выделил области, в которых возникает ошибка, а также код, который я пытался использовать для решения проблемы.
Любой совет относительно того, как я мог бы исправить эти ошибки, высоко ценится.
Я не включил полные файлы .cpp, так как они довольно большие, но я включу ссылку на pasteBin с полным сценарием.
GrapicsManager.h
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Room.h"
#include "Robot.h"
class GraphicsManager
{
public:
Room* room; //This does not Flag Up Errors
Robot* robot; //This does not Flag Up Errors
Robot.h
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System/String.hpp>
#include "GraphicsManager.h"
//#include "Room.h" //This what i had
class Room; //This is what i changed
//class GraphicsManager; //Wasnt sure if i should use it this
//way
class Robot
{
public:
//Graphics Variables
Room* room; //This works after the change
Robot* robot; //This works after the change
GraphicsManager *gm; //This throughs up the error
//This Is what i attemped to use with no effect
//GraphicsManager* gm = new GraphicsManager(room, robot);
Robot.cpp https://pastebin.com/Xd1A3Vii
#include "Robot.h"
Robot::Robot()
{
gm = new GraphicsManager(room, robot); //This tells me gm is
//not declared
this->room = room; //This does not flag up errors
this->robot = robot; //This does not flag up errors
//Room &room = *rm; // attempted to use this but decided not
//to
}
Room.h
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/System/String.hpp>
#include "GraphicsManager.h" //
//#include "Robot.h" //what i orginally had
//class GraphicsManager; //i decided not to do it this way
class Robot; //What i changed it to
class Room
{
public:
//Reference to other classes
Room* room; //This doesnt throw errors
Robot* robot; //This doesnt throw errors
//Refference to graphics manager
GraphicsManager *gm; //This throws the three errors mentioned
};
Room.cpp https://pastebin.com/6R6vnVfy
#include "Room.h"
Room::Room()
{
gm = new GraphicsManager(room, robot);
this->room = room;
this->robot = robot;