#I need help with base class undefined.

158 messages · Page 1 of 1 (latest)

spice spire
#

I have Interface Which inherits from other interface. I also have two classes that inherit from the second interfac. the second interface has a cpp file.

wicked jacinthBOT
#

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.

spice spire
#

can you help me?

clear charm
#

bro with the question you should have pasted the code

spice spire
#
#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
};
clear charm
#

I didn't get your question

spice spire
#

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

clear charm
spice spire
#

IRequestHandler, IRoomMemberRequestHandler and RoomMemberRequestHandler are in the same folder

clear charm
#

oh k then the other classes?

spice spire
#

what other classes?

clear charm
#

RoomManager etc

spice spire
clear charm
#

so the problem is in your class IRoomMemberRequesrHandler

#

check whether you have inherited properly from it

clear charm
spice spire
#

In the handlers folder

clear charm
#

so which system are u using?

spice spire
spice spire
clear charm
#

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

clear charm
#

ok open powershell

#

go to your directory where you are working in

#

using "cd"

#

because it's tough to understand your directory structure

spice spire
#

Use ls?

#

Do I need to give args?

hybrid herald
#

the error list is generally useless unless the error is trivial

hybrid herald
#

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

spice spire
hybrid herald
#

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

spice spire
#

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);
};
clear charm
#

oh there is some error with override

hybrid herald
clear charm
#

yeah

hybrid herald
#

because this smells like a circular include

hybrid herald
#

so if you hide any of the include it's going to be complicated

#

ok, how much of IRequestHandler.h have you shown/hidden

spice spire
#
#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);
};
clear charm
#

see the error of "override" comes when you use "virtual " keywords where it isn't required

spice spire
hybrid herald
#

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

spice spire
hybrid herald
clear charm
spice spire
#

Trivia game

clear charm
#

oh nice

hybrid herald
clear charm
#

it looks like 1 year or 2 years of coding

spice spire
#

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
};
spice spire
clear charm
#

oh k

spice spire
#

the end of the second year

clear charm
#

cool

#

why did you include two classes in this file?

spice spire
hybrid herald
wicked jacinthBOT
#

@spice spire Has your question been resolved? If so, type !solved :)

hybrid herald
# spice spire thank you

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

spice spire
#
#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);
};
hybrid herald
#

I meant the cpp, not the h

spice spire
#
#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;
}
spice spire
hybrid herald
#

no

#

I'd say you probably shouldn't

#

but for some reason it is included anyway

hybrid herald
spice spire
#

it isnt included

spice spire
hybrid herald
#

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

hybrid herald
spice spire
#
#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;

};
hybrid herald
#

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

spice spire
#

maybe we can start a call and ill share my screen so you can do it easier

#

?

hybrid herald
#

Project Settings -> Configuration Properties -> C/C++ -> Advanced -> Show Includes

#

then recompile

#

and reshare the compiler output

hybrid herald
#

yes

spice spire
#

just a sec

hybrid herald
#

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

hybrid herald
#

then that's you're issue

#

you have circular includes

spice spire
#

so to fix this issue i need to delete the include in this file?

hybrid herald
#

IRoomMemberRequestHandler.h -> RequestHandlerFactory.h -> RoomMemberRequestHandler.h -> IRoomMemberRequestHandler.h

hybrid herald
#

only include what you use/need

#

forward declare the rest

#

then include all you need in source files

spice spire
#

thank you

hybrid herald
spice spire
#

👍

clear charm
#

@hybrid herald how about he used module feature of c++20

hybrid herald
clear charm
#

oh you are right

spice spire
hybrid herald
#

?

#

what file

spice spire
#

how can i use class without including its file?

hybrid herald
#

and what include

#

which class, and where

hybrid herald
#

why do you include RequestHandlerFactory.h in IRoomMemberRequestHandler.h

#

based on what you shared, IRoomMemberRequestHandler.h doesn't need the include

spice spire
#

RequestHandlerFactory* m_handlerFactory;
field in IRoomMemberRequestHandler.h

hybrid herald
#

you don't use the factory inside the header

hybrid herald
hybrid herald
#

you only need to know that there is a class named RequestHandlerFactory

#

you aren't using the definition of RequestHandlerFactory

spice spire
hybrid herald
#

you never use the members of RequestHandlerFactory

spice spire
#

ok

hybrid herald
#

you never try to do m_handlerFactory->whatevermember

#

so you don't need the include

hybrid herald
spice spire
#
#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

#

?

hybrid herald
spice spire
#

ok i got it

#

thank you so much

#

I think i solved it

#

thank you

clear charm
#

cool bro

spice spire
#

!solved