Error on my code

I have this error in Visual Studio

Error 2 error C2447: '{' : missing function header (old-style formal list?)

And this is my code
----------------------
MAIN.CPP

1
2
3
4
5
6
7
8
9
10
11
#include "stdafx.h"
#include "Juego.h"

int main()
{

	Juego miJuego;
	miJuego.Loop();

	return 0;
}

----------------------------------
STDAFX.H

1
2
3
4
5
6
7
8
9
10
#pragma once

//#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>
#include <SFML\System.hpp> 

-------------------------------
JUEGO.H

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
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include "stdafx.h"
#include "PlayerCrosshair.h"

using namespace sf;

class Juego
{

	RenderWindow *_wnd;
	PlayerCrosshair *player;

public:
	Juego()
	{
		_wnd = new RenderWindow(VideoMode(800, 600), "Crosshair)");
		player = new PlayerCrosshair();
	}

	void Loop()
	{
		while (_wnd->isOpen())
		{
			ProcesarEventos();
			Actualizar();
			Dibujar();
		}
	}

	void ProcesarEventos()
	{
		Event evt;
		while (_wnd->pollEvent(evt))
		{
			switch (evt.type)
			{
				case Event::Closed:
					_wnd->close();
					break;
			}
		}
	}

	void Actualizar()
	{

	}

	void Dibujar()
	{
		_wnd->clear(Color::White);
		player->Dibujar(_wnd);
		_wnd->display();
	}
};

--------------------
PLAYERCROSSHAIR.H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class PlayerCrosshair
{
	Texture crossTex;
	Sprite crossSprite;

public:
	PlayerCrosshair()
	{
		//cargar y config la imagen
		crossTex.loadFromFile("crosshair.png");
		crossSprite.setTexture (crossTex);
	}

	void Dibujar(RenderWindow *wnd)
	{
		wnd->draw(crossSprite);
	}


};



I cannot find where is this error. Because it says it is in line 3 in main.cpp.
Last edited on
> Because it says it is in line 3 in main.cpp.
that is not what you've posted
Error 2 error C2447: '{' : missing function header (old-style formal list?)
don't see anything about line number or file.

So I guess that that wasn't the full error message.
If you don't understand their meaning don't go cropping parts.

If that's really all what your compiler said, then it's pure garbage. Stop using it.


Your error is in PLAYERCROSSHAIR.H when you tried to use `Texture', `Sprite' and `RenderWindow' withouth specifying that they belong to the `sf' namespace.
1
2
3
	sf::Texture crossTex;
	sf::Sprite crossSprite;
	void Dibujar(sf::RenderWindow *wnd)



don't using namespace on headers, any file that includes it gets polluted.
Also, make your headers self-contained. PLAYERCROSSHAIR.H should include the relevants SFML headers, and it is missing the headers guards.
Last edited on
Topic archived. No new replies allowed.