Deriving from a interface errors, dont quite understand

Since i seem to be beign ignored ill try here..

This error is annoying, Im kinda new to this design please help:

error C2061: syntax error : identifier 'GameObject'
InputComponent::Update' : function does not take 1 arguments

error C2259: 'PlayerInputComponent' : cannot instantiate abstract class
1> due to following members:
1> 'void InputComponent::Update(void)' : is abstract

InputComponent:

1
2
3
4
5
6
7
 #pragma once
#include "GameObject.h"
class InputComponent
{
public:
	virtual void Update(GameObject &obj) = 0;
};


PlayerInputComponent:
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once
#include "InputComponent.h"
#include "GameObject.h"
class PlayerInputComponent : public InputComponent
{
public:
	virtual void Update(GameObject &obj)
	{
		//Check input here..
	}
private:
};


GameObject:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once
#include "InputComponent.h"
#include "PhysicsComponent.h"
#include "RenderComponent.h"
class GameObject
{
public:
	int x, y;
	int velocity;

	GameObject(InputComponent *input, PhysicsComponent *physics, RenderComponent *render) 
		: input_(input), 
		physics_(physics),
		render_(render) {};

	virtual void Update()
	{
		input_->Update(*this);
		physics_->Update(*this);
		render_->Update(*this);
	}

private:
	InputComponent *input_;
	PhysicsComponent *physics_;
	RenderComponent *render_;
	
};


Any help would be great
Last edited on
Look, the following code works:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>

using namespace std;

class GameObject;

class InputComponent
{
        public:
                virtual void Update(GameObject &obj) = 0;
};              

class PlayerInputComponent : public InputComponent
{
        public:         
        virtual void Update(GameObject &obj)                            
        {               
               cerr << "Updated\n";                                        
        }                                                       
};                                              

class GameObject{
public: 
        int x, y;                       
        int velocity;
                                        
        GameObject(InputComponent *input): input_(input){}
                                        
        virtual void Update()                                                   
        {                                                                               
                input_->Update(*this);                                                                                          
        }

private:
        InputComponent *input_;
                                                                        
};                                                              

int main(){
        InputComponent* t = new PlayerInputComponent;
        GameObject q(t);
        q.Update();
        cerr << "Hello\n";
}  


I think the problem is how you initialize you GameObject.
why doesnt it work when i put it into seperate classes? says overload +2 or something
May you show the part of code where you initialize you GameObject.
It is difficult to say what is wrong not seeing the whole.
Sure! :D

here is how i initialize my GameObject
a side note: Do i need to forward declare anything in any class?

implementation code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <allegro5\allegro.h>
#include <iostream>

#include "GameObject.h"
#include "InputComponent.h"
#include "PlayInputComponent.h"

int main()
{
	GameObject *Player = new GameObject(new PlayInputComponent);


	Player->Update();

	std::cin.peek();

	return 0;
}
I don't understand :)
Maybe, indeed, you should make a forward declaration of GameObject in InputComponent.h and PlayInputComponent.h.
http://www.cplusplus.com/forum/articles/10627/ (point 4)

1
2
3
GameObject *Player = new GameObject( //¿why dynamic allocation?
   new PlayInputComponent
);
Last edited on
Thanks for the help but im still confused, I dont know where i am going wrong, i have done the includes and im still getting the '+1 overloaded' error.

Also what is wrong with the way im declaring a new GameObject ne555?

The game objects takes a component when created so im confused, also im dynamically allocating it because i want to manually handle it?
> im still getting the '+1 overloaded' error.
http://www.cplusplus.com/forum/articles/40071/#msg216270

> Also what is wrong with the way im declaring a new GameObject
It is ugly, error prone and inefficient.
What would you suggest?

edit:

Sorry, this question -> im still getting the '+1 overloaded' error.

tfityo suggested a design i was implementing that works, whenever i put it into classes (see the beginning of my post for it) it throws a few error for me.

I have solved most of the errors by forward declaring some classes inside others. Now the only problem im getting is the '+1 overloaded'. This is something im getting when i declare an object like this:
GameObject *Player = new GameObject(new PlayInputComponent);

However the program runs fine but i get this error anyways. Im just trying to figure out the cause of this problem and if theres any other creation of the object

Edit 2:

BTW im following this tutorial:
http://gameprogrammingpatterns.com/component.html
Last edited on
Your code won't compile as is, so it's hard to say what the issue may be.

Post code that compiles and illustrates the problem if you want help.

Example of minimal compilable code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>

class GameObject ;

class InputComponent
{
public:
    virtual void Update(GameObject &obj) = 0;
};


class PlayerInputComponent : public InputComponent
{
public:
    virtual void Update(GameObject &obj)
        { std::cout << "PlayerInputComponent invoked.\n" ; }
};

class GameObject
{
public:
    GameObject(InputComponent *input ) 
        : input_(input) {}

    virtual void Update()
        { input_->Update(*this); }

private:

    InputComponent *input_;
};

#include <iostream>

int main()
{
    PlayerInputComponent pic ;
    GameObject Player(&pic);
    Player.Update();
}

> Now the only problem im getting is the '+1 overloaded'.
¿have you followed the link? I doubt that all you get is `error: +1 overloaded'

> However the program runs fine but i get this error anyways
¿who is giving you that error? If the build failed, then you can't run the program.
I appreciate your help and i hope your not getting frustrated(at least as i am lol) but the build isnt actually giving me the error, when i hold my mouse over the line where i dynamically create the object, it displays the error or warning


EDIT:

Also Cire, when i do EXACTLY that code and put it into classes, i get a '+2 overload' error when i hold my mouse over GameObject that i created, dynamically created or not.. im so confused -_-
Last edited on
Topic archived. No new replies allowed.