0

I already know what this error means and what is causing it. But I need a way to around actually. I need an object to pass in the constructors of other classes, but I need to define the object in its class.

Code what gives the error:

#pragma once
#include "Smash.h"
#include "Window.h"
#include "Input.h"
#include "Game.h"
#include "Render.h"

class Smash {
public:
    Smash smash; ///I NEED THE smash OBJECT TO PASS IN THE OTHER CLASSES, ERROR APPEARS HERE.
    Game game(smash);
    Window win(smash);
    Render render(smash);
    Input input(smash);
};

The smash object is causing the error because it is in the header class itself.

I just need a way to go around or something.

Sorry for bad English, thanks in advance.

OpenGLmaster1992
  • 241
  • 1
  • 4
  • 12
  • You can only have a pointer or reference to a incomplete type. You might have a design problem with your program if you need this. – NathanOliver Dec 01 '15 at 18:34
  • If you want *one* instance of Smash, make it `static`. You can't have a `Smash` as a member in `Smash`, the class would be of infinite size. – melak47 Dec 01 '15 at 18:34
  • You want to say that you can't create a `Smash` without first having created a `Smash`? That doesn't make sense. –  Dec 01 '15 at 18:34
  • You have an inherent flaw in your design, it will never work. On construction of a `Smash` object your program would have to construct another `Smash` object which has to construct another... and so on. Infinite recursion. – Cybran Dec 01 '15 at 18:35
  • You need to describe what you're trying to achieve by doing this, because actually doing it is impossible. – interjay Dec 01 '15 at 18:38
  • Okay, so I need the smash object for use in other(game,win,render,input) classes. That is why I am passing the object into their constructor. I also need all the objects defined public, that is why they are public in the header file. – OpenGLmaster1992 Dec 01 '15 at 18:45

0 Answers0