1

I'm 13 and still quite new to OpenGL and graphical libraries in general. Currently I'm working on a OpenGL project and I have multiple errors stating that a base class is undefined, for example, 'GameObject' base class undefined. I have tried a multitude of things such as making sure all the header files only used pragma once instead of a mix of pragma and ifndef. I have also made sure that all my includes are in order and even forward declared important classes.

Here's a small snippet of a class where it has inherited GameObject and included the GameObject header file but still states that the header class is undefined:

#pragma once

class Game;

#include "game.h"
#include <glm/glm.hpp>
#include <vector>
#include "GameObject.h"

#include "shaderclass.h"
#include "Camera.h"




class Paddle : public GameObject {
    public:


        enum CONTROLTYPE { WASD, ARROW };
        CONTROLTYPE type;

        Paddle(glm::vec3 position, glm::vec3 scale, CONTROLTYPE type, glm::vec3 velocity);

        void update(Game* g, GLFWwindow* gameWindow);
    
};

(I did not forward declare GameObject but if I did it would still output the same error)

GameObject header file:

#pragma once

class Game;
#include "game.h"
#include "shaderclass.h"
#include"ROML.h"
#include<glm/glm.hpp>
#include "Mesh.h"



class GameObject {
public:
//etc...

Full build error:

Error   C2504   'GameObject': base class undefined  OpenPong    

Unfortunately, due to the size of the project I cant provide a minimal reproducible example here but here's the GitHub repository if you would like to look further into the code: https://github.com/ghostly-developer/OpenPong/tree/%232-classes

I also don't have any intellisense errors that could've caused this.

Thanks!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
AsianMario
  • 37
  • 1
  • 4
  • Please **[edit]** your question with an [mre] or [SSCCE (Short, Self Contained, Correct Example)](http://sscce.org). This also include giving us the full error message. Paraphrasing error messages often loses vital information. – NathanOliver Jul 19 '21 at 12:37
  • 1
    Does your `GameObject header file` include -- either directly or indirectly -- the header in which `Paddle` is defined? – G.M. Jul 19 '21 at 12:43
  • C++ is the most complicated general programming language in use today. After about 3-5 years of full-time study, guided by a well-written C++ textbook, one would typically have average knowledge and understanding of many core C++ fundamental principles: virtual inheritance, polymorphism, overloading, containers, iterators, algorithms, templates, variadic templates, concepts, constraints, and many others. And only at that point someone might have a solid basis to use to branch out in various highly technical areas, like special-purpose graphical libraries, which need expert-level C++ knowledge. – Sam Varshavchik Jul 19 '21 at 12:44
  • @G.M Yes, GameObject does include the header file where the `paddle` class is defined. – AsianMario Jul 19 '21 at 12:45
  • 1
    You have a bunch of circular includes. `game.h` includes a bunch of files, and all of those files include `game.h` which is not goin to work. – NathanOliver Jul 19 '21 at 12:45
  • 1
    You should only have an `#include` for the symbols that are used in that file. It is the **include what you use** principle. Avoid relying on indirect `#include`. Not sure if that is an issue in this case, but for the code snippets provided it looks suspect. – Eljay Jul 19 '21 at 12:46
  • @NathanOliver I see, although game.h does need all the files that are included and all the files that include `game.h` also need the header file. Is there a work-around or would I have to re-write my code? – AsianMario Jul 19 '21 at 12:48
  • 1
    You need to pick out the *real* dependencies. e.g. the class `Paddle` obviously needs to see the full class definition for `GameObject` since it inherits from it. But why does `GameObject` need to know about `Paddle`? It doesn't based on the code shown. Without seeing a [mcve] all anyone can really do is guess. – G.M. Jul 19 '21 at 12:56
  • I'll take a good look again and try to sort out my includes, hopefully it works. – AsianMario Jul 19 '21 at 12:59
  • Quick update: I've managed to drop the number the errors quite drastically, instead of including some of the header files specifically I instead forward declared the classes instead. So far it's been fixing most of the issues. – AsianMario Jul 19 '21 at 13:09
  • The error *'GameObject' base class undefined* has nothing to do with OpenGL. This is a c++ problem. – Rabbid76 Jul 19 '21 at 14:37
  • 1
    @SamVarshavchik I'm not sure. I started learning GL when I was 15, with ~3 months of C++ experience, and it was ok. The ability to draw pretty pictures on the screen is a major motivation boost. – HolyBlackCat Jul 19 '21 at 14:52

0 Answers0