I have a header file causing me several errors. It contains a class definition, then I have a *.cpp file with the function definitions.

Header:

#ifndef DOT_H
#define DOT_H

#include "SDL/SDL.h"
#include <vector>

class Dot
{
private:
	int x, y;
	int xVel, yVel;
	vector<SDL_Rect> box;
	
	bool check_collision( vector<SDL_Rect> &A, vector<SDL_Rect> &B );
	void shift_boxes();

public:
	Dot( int newX, int newY );

	int get_x();
	int get_y();

	vector<SDL_Rect> &get_rects();

	void handle_input( SDL_Event *trigger );
	void move( vector<SDL_Rect> &rects );
};

#endif

The *.cpp code is a bit lengthy, so I won't post it unless it is needed. Anyway, here's the errors I'm getting:

c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(12) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(12) : error C2238: unexpected token(s) preceding ';'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(14) : error C2061: syntax error : identifier 'vector'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(23) : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(23) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(23) : error C2238: unexpected token(s) preceding ';'
c:\documents and settings\compaq_administrator\my documents\visual studio 2008\projects\sdl_tutorials\per pixel collision\per pixel collision\dot.h(26) : error C2061: syntax error : identifier 'vector'

I'm also getting 80 other errors due to these ones.

The thing I can't figure out is if I put the class definition and function definition code into my main *.cpp I don't get any errors. I've been trying to figure this one out for a while. I've used headers and classes before, and it is usually a simple matter, but this one is beyond me.

Recommended Answers

All 3 Replies

Have you tried adding

using namespace std;

before defining the Dot class ?

Or perhaps instead

using std::vector;

Thanks, it compiles now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.