-3

I am creating an engine:

#include "Engine.h"

class Engine{
    
    GraphicsManager graphicsManager;
  
    public: 
    
        
        //Other managers
        
        void Start(){
            
          graphicsManager.Start();
           
        }
           
        
        void Shutdown(){
            
            graphicsManager.Shutdown();
        }
        
        void RunGameLoop(  ){

        }

           
                // Manage timestep
};
#ifdef ENGINE_H
#define ENGINE_H
#include "GraphicsManager.h"
#include "spdlog/spdlog.h


#pragma once
class Engine{

        private:
            GraphicsManager graphicsManager;
            InputManager inputManager;
            AudioManager audioManager;


        public:
            Engine();
            ~Engine();

            //start up managers
            void Start();
            //runs game loop
            void RunGameLoop();
            //shuts down managers
            void Shutdown();

        
};
    
#endif // ENGINE_H

...and keep getting an undeclared identifier error even though i declare the graphic manager in the header class:

'graphicsManager': unknown override specifier
src\Engine.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
src\Engine.cpp(15): error C2065: 'graphicsManager': undeclared identifier
src\Engine.cpp(22): error C2065: 'graphicsManager': undeclared identifier

I tried changing it to a pointer, puting the #Includes in the cpp, and I expect it to not give me the error an compile correctly.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Mitch
  • 1
  • 2
  • 2
    Why is `class Engine` declared twice ? – Richard Critten Aug 30 '23 at 19:18
  • 2
    Please try to create a [mre] to show us. – Some programmer dude Aug 30 '23 at 19:18
  • Make sure that `GraphicsManager.h` does not include `Engine.h`. If it does that is the bug that produces the errors you see. @RichardCritten mentioned a second bug. You should only have `class Engine{` in the header and not it the cpp file. Putting it in both attempts to create 2 different `Engine` classes. – drescherjm Aug 30 '23 at 19:18
  • `class Engine{ ... }` in what I presume to be the implementation file rather than the header redefines the `Engine` class. Since it's different from the definition in the header, bad smurf happens. All you want to do in the implementation file is define the member functions. Eg: `void Engine::Start(){ ... }` , `void Engine::Shutdown(){ ... }`, etc... – user4581301 Aug 30 '23 at 19:19
  • Side note: If you write less code at a time you'll find fundamental mistakes like this before you repeat them and have to fix essentially the same mistake several times. Don't let bugs build up because they hide each other by making the error messages and runtime behaviour more inscrutable. – user4581301 Aug 30 '23 at 19:21
  • Where's the minimal content for `Engine.cpp`? I didn't see it in your post. – Thomas Matthews Aug 30 '23 at 19:24
  • 1
    Very important: Don't guess at C++ syntax. The success rate is too low to be worth it, and the error messages you get when you're wrong are cryptic because the compilers assume you know what you are doing. Instead [get a good book](https://stackoverflow.com/q/388242/4581301) and start at the beginning, working your way through the examples and posed problems. – user4581301 Aug 30 '23 at 19:28
  • you're missing a quote on the end of `spdlog/spdlog.h` – Alan Birtles Aug 30 '23 at 19:40
  • @ThomasMatthews I dont have the other content yet, we're basically followiing like a guide and trying to get to check points and the this checkpoint is getting the graphics manager window to open but I cant get to that part till i figure out the identifier bit – Mitch Aug 30 '23 at 20:37
  • @user4581301 Sorry, it's been a few months and im still gathering my bearings on it! It's just hard to gather my bearings and do the assigments at the same time. Thank you for the link, i'll take a look! – Mitch Aug 30 '23 at 20:39
  • @Mitch: The errors from the compiler say `Engine.cpp(#)...`. So, where's the code causing the compiler errors? – Thomas Matthews Aug 30 '23 at 21:06
  • From the fundamental mistakes in the code you've provided you owe it to yourself at least a review of the basics before proceeding. This may not be the in depth study I recommended above assuming you were brand-new to C++, but you need to take some time off this project to refresh and spin the brain back up. You're going to have enough real problems soon enough, so why waste time you can spend on them on misremembering the basics? – user4581301 Aug 30 '23 at 21:21

0 Answers0