#I need help with base class undefined.
158 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
🙏
can you help me?
bro with the question you should have pasted the code
#pragma once
#include "IRequestHandler.h"
#include "IRoomMemberRequestHandler.h"
class RoomMemberRequestHandler : public IRoomMemberRequestHandler {
RoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler)
: IRoomMemberRequestHandler(room, user, roomManager, handler) {}
RoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db)
: IRoomMemberRequestHandler(room, user, roomManager, db) {}
virtual bool isRequestRelevant(RequestInfo information) override;
virtual RequestResult handleRequest(RequestInfo information) override;
private:
RequestResult leaveRoom(RequestInfo information);
};
#pragma once
#include "IRequestHandler.h"
#include "../Infrastructure/RequestHandlerFactory.h"
#include "../Managers/Room.h"
#include "../Managers/RoomManager.h"
#include "../Managers/LoggedUser.h"
#include "../Infrastructure/IDataBase.h"
class IRoomMemberRequestHandler : public IRequestHandler
{
public:
IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler);
IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db);
~IRoomMemberRequestHandler();
virtual bool isRequestRelevant(RequestInfo information) = 0; // Check if the request is relevant
virtual RequestResult handleRequest(RequestInfo information) = 0; // Handle the request
protected:
Room m_room;
LoggedUser m_user;
RoomManager& m_roomManager;
RequestHandlerFactory* m_handlerFactory;
RequestResult getRoomState(RequestInfo information);
};
// Interface for request handlers
class IRequestHandler
{
public:
virtual bool isRequestRelevant(RequestInfo information) = 0; // Check if the request is relevant
virtual RequestResult handleRequest(RequestInfo information) = 0; // Handle the request
};
I didn't get your question
i have a c2504 error.
Severity Code Description Project File Line Suppression State Details
Error C2504 'IRoomMemberRequestHandler': base class undefined MagshiTriviaBackend C:\Users\itayb\Desktop\Trivia\trivia_2024_itaybenshushan_avshalomnevat\solution\source\Handlers\RoomAdminRequestHandler.h 7
show me your directory structure
IRequestHandler, IRoomMemberRequestHandler and RoomMemberRequestHandler are in the same folder
oh k then the other classes?
what other classes?
RoomManager etc
they are in Handlers folder, all other are in Managers folder, or Infrastructure. all of this folders are in the main project folder
so the problem is in your class IRoomMemberRequesrHandler
check whether you have inherited properly from it
where is IRequestHandler defined?
In the handlers folder
so which system are u using?
This class doesn’t have cpp file
Wdym system?
are you using windows or Linux...if windows open powershell and type ls and take a screenshot of it and send
in your working directory
Ok
I use windows
ok open powershell
go to your directory where you are working in
using "cd"
because it's tough to understand your directory structure
this looks like the "error list", can you share the compiler output instead?
the error list is generally useless unless the error is trivial
Sure
and for external people that don't have your entire code on-hand, it just skips too much information
assuming you're using VS, look for the output tab/window/pane/panel
check the drop down menu to make sure it shows the build output
ok good
ok, can you share RoomAdminRequestHandler.h
it's complaining that the base class of RoomAdminRequestHandler is undefined, and that base class is IRoomMemberRequestHandler, so either you missed an include in RoomMemberRequestHandler.h, or there's some circular include going on
actually I guess that's the first one you shared
the RoomAdminRequestHandler is similar to this:
#pragma once
#include "IRequestHandler.h"
#include "IRoomMemberRequestHandler.h"
class RoomMemberRequestHandler : public IRoomMemberRequestHandler {
RoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler)
: IRoomMemberRequestHandler(room, user, roomManager, handler) {}
RoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db)
: IRoomMemberRequestHandler(room, user, roomManager, db) {}
virtual bool isRequestRelevant(RequestInfo information) override;
virtual RequestResult handleRequest(RequestInfo information) override;
private:
RequestResult leaveRoom(RequestInfo information);
};
oh there is some error with override
that's tied to the base class being "undefined"
yeah
it's similar, you didn't skip any of the include?
because this smells like a circular include
no
so if you hide any of the include it's going to be complicated
ok, how much of IRequestHandler.h have you shown/hidden
#pragma once
#include "IRequestHandler.h"
#include "IRoomMemberRequestHandler.h"
class RequestHandlerFactory;
class RoomAdminRequestHandler : public IRoomMemberRequestHandler {
public:
RoomAdminRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler)
: IRoomMemberRequestHandler(room, user, roomManager, handler) {}
RoomAdminRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db)
: IRoomMemberRequestHandler(room, user, roomManager, db) {}
virtual bool isRequestRelevant(RequestInfo information) override;
virtual RequestResult handleRequest(RequestInfo information) override;
private:
RequestResult closeRoom(RequestInfo information);
RequestResult startGame(RequestInfo information);
};
see the error of "override" comes when you use "virtual " keywords where it isn't required
wdym hide includes?
a priori if IRoomMemberRequestHandler.h defines IRoomMemberRequestHandler then the only way this can break is if IRequestHandler and IRoomMemberRequestHandler have some circular include going on
that is not the issue, it comes because there is a problem with the base class
oh k
as in, you haven't copy-pasted the whole file
can I ask what is this project about?
Trivia game
oh nice
like the last code snippet isn't the entire IRequestHandler.h file, is it?
it looks like 1 year or 2 years of coding
the IRequestHandler snippet is not the entire file
this is:
#pragma once
#include <ctime>
#include <vector>
class IRequestHandler;
class RequestHandlerFactory;
// Enumeration for different request types
enum class RequestId
{
LOGIN = 101,
SIGNUP = 102,
LOGOUT = 103,
GET_ROOMS = 104,
GET_PLAYERS = 105,
JOIN = 106,
CREATE_ROOM = 107,
GET_STATS = 108,
GET_HIGH_SCORE = 109,
CLOSE_ROOM = 110,
START_GAME = 111,
GET_ROOM_STATE = 112,
LEAVE_ROOM = 113,
};
enum class STATUS
{
FAILED = 0,
SUCCESS = 1,
};
// Struct for holding the result of a request
struct RequestResult
{
std::vector<unsigned char> response; // Response data
IRequestHandler* newHandler = nullptr; // Pointer to a new request handler
};
// Struct for holding information about a request
struct RequestInfo
{
RequestId id; // Request ID
time_t receivalTime; // Time when request was received
std::vector<unsigned char> buffer; // Request data buffer
};
// Interface for request handlers
class IRequestHandler
{
public:
virtual bool isRequestRelevant(RequestInfo information) = 0; // Check if the request is relevant
virtual RequestResult handleRequest(RequestInfo information) = 0; // Handle the request
};
it is my second year...
oh k
the end of the second year
Because the debugger doesnt know them when reading this file,
looks fine, it doesn't have the issue I was looking for, let me go over the files I've asked already to check if I haven't missed something
thank you
@spice spire Has your question been resolved? If so, type !solved :)
can you share IRoomMemberRequestHandler.cpp
like everything until at least the include of RoomAdminRequestHandler.h
if it doesn't include that header, then it's an indirect inclusion and you'll have to track that down
#pragma once
#include "IRequestHandler.h"
#include "../Infrastructure/RequestHandlerFactory.h"
#include "../Managers/Room.h"
#include "../Managers/RoomManager.h"
#include "../Managers/LoggedUser.h"
#include "../Infrastructure/IDataBase.h"
class IRoomMemberRequestHandler : public IRequestHandler
{
public:
IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler);
IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db);
~IRoomMemberRequestHandler();
virtual bool isRequestRelevant(RequestInfo information) = 0; // Check if the request is relevant
virtual RequestResult handleRequest(RequestInfo information) = 0; // Handle the request
protected:
Room m_room;
LoggedUser m_user;
RoomManager& m_roomManager;
RequestHandlerFactory* m_handlerFactory;
RequestResult getRoomState(RequestInfo information);
};
I meant the cpp, not the h
#include "IRoomMemberRequestHandler.h"
#include "../Response/JsonResponsePacketSerializer.h"
#include "../Request/JsonRequestPacketDeserializer.h"
IRoomMemberRequestHandler::IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler) : m_room(room), m_user(user), m_roomManager(roomManager), m_handlerFactory(handler)
{
}
IRoomMemberRequestHandler::IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db) : m_room(room), m_user(user), m_roomManager(roomManager), m_handlerFactory(new RequestHandlerFactory(db))
{
}
IRoomMemberRequestHandler::~IRoomMemberRequestHandler()
{
delete m_handlerFactory;
}
RequestResult IRoomMemberRequestHandler::getRoomState(RequestInfo information)
{
RequestResult result;
GetRoomStateResponse response;
try {
RoomData data = m_room.getData();
response.answerTimeout = data.timePerQuestion;
response.hasGameBegun = data.isActive;
response.players = m_room.getUsers();
response.questionCount = data.numberOfQuestions;
response.status = (unsigned int)STATUS::SUCCESS;
result.newHandler = nullptr; // fix later
}
catch (...) {
response.status = (unsigned int)STATUS::FAILED;
result.newHandler = nullptr;
}
result.response = JsonResponsePacketSerializer::serializeResponse(response);
return result;
}
should I include this file in the cpp file of its base class?
if that's the entire thing then you have something very weird going on
it isnt included
that is the entire file
because the most likely header to end up tiggering an indirect include is IRoomMemberRequestHandler.h itself tbh
or at least I don't see why the json thingies would include RoomMemberRequestHandler.h
actually what's in Managers/RoomManager.h
#pragma once
#include <unordered_map>
#include "Room.h"
class RoomManager
{
public:
void createRoom(LoggedUser user, RoomData data);
void deleteRoom(unsigned int id);
unsigned int getRoomState(unsigned int id);
std::vector<Room> getRooms();
Room& getRoom(unsigned int id);
private:
// UML is not synchonaized with it self, what is the type RoomID?
std::unordered_map<unsigned int, Room> m_rooms;
};
if this one doesn't show something fishy, I guess I'll have to dig up some option to have a more verbose compiler output
Project Settings -> Configuration Properties -> C/C++ -> Advanced -> Show Includes
then recompile
and reshare the compiler output
turn this on?
yes
right, I guess you can compile twice, so that you only share the errors
nvm, I'll just ctrl+f
ok, can you show RequestHandlerFactory.h
or check if that thing includes RoomMemberRequestHandler.h
it does
so to fix this issue i need to delete the include in this file?
IRoomMemberRequestHandler.h -> RequestHandlerFactory.h -> RoomMemberRequestHandler.h -> IRoomMemberRequestHandler.h
generally speaking you should have as few include as possible in headers
only include what you use/need
forward declare the rest
then include all you need in source files
ok
ok Ill go over the folder and do it for each file
thank you
based just on that you don't need to include the factory, just forward declare it
👍
@hybrid herald how about he used module feature of c++20
not gonna solve anything if he doesn't structure his dependencies properly while translating his headers to be modules instead
oh you are right
but in each file i need the include...
how can i use class without including its file?
in this loop
.
why do you include RequestHandlerFactory.h in IRoomMemberRequestHandler.h
based on what you shared, IRoomMemberRequestHandler.h doesn't need the include
RequestHandlerFactory* m_handlerFactory;
field in IRoomMemberRequestHandler.h
you don't use the factory inside the header
i do
that's solved by using forward declarations, like I said in the message where I said the include isn't used
no, you aren't
you only need to know that there is a class named RequestHandlerFactory
you aren't using the definition of RequestHandlerFactory
oh so i should 4wd declare the factory
you never use the members of RequestHandlerFactory
ok
you never try to do m_handlerFactory->whatevermember
so you don't need the include
I suggested the forward declaration, yes
i do it in the .cpp file
#include "IRoomMemberRequestHandler.h"
#include "../Response/JsonResponsePacketSerializer.h"
#include "../Request/JsonRequestPacketDeserializer.h"
IRoomMemberRequestHandler::IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, RequestHandlerFactory* handler) : m_room(room), m_user(user), m_roomManager(roomManager), m_handlerFactory(handler)
{
}
IRoomMemberRequestHandler::IRoomMemberRequestHandler(Room room, LoggedUser user, RoomManager roomManager, IDataBase* db) : m_room(room), m_user(user), m_roomManager(roomManager), m_handlerFactory(new RequestHandlerFactory(db))
{
}
IRoomMemberRequestHandler::~IRoomMemberRequestHandler()
{
delete m_handlerFactory;
}
RequestResult IRoomMemberRequestHandler::getRoomState(RequestInfo information)
{
RequestResult result;
GetRoomStateResponse response;
try {
RoomData data = m_room.getData();
response.answerTimeout = data.timePerQuestion;
response.hasGameBegun = data.isActive;
response.players = m_room.getUsers();
response.questionCount = data.numberOfQuestions;
response.status = (unsigned int)STATUS::SUCCESS;
result.newHandler = nullptr; // fix later
}
catch (...) {
response.status = (unsigned int)STATUS::FAILED;
result.newHandler = nullptr;
}
result.response = JsonResponsePacketSerializer::serializeResponse(response);
return result;
}
so should i include it here? in the cpp file
?
that's what I said back there
cool bro
!solved