Hey everyone.
I'm a (A-bit-more-than-beginner-but-not-really-good-too-)Java Developer learning C++, and I decided to program a really simple game with SFML in order to get comfortable with C++.
I wrote a few lines of codes, and tried running it for the first time - And I directly get a hundred of compiler errors. This isn't bad nor unusual in itself, but the thing bothering me, is that those errors seem to be completely "off-topic": I get Syntax-Errors where OBVIOUSLY everything is alright.
First, here are all the types of errors that I get:
- C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I already read quite a few articles and forum-posts on this error, but unfortunately none of the problems seem to apply to me. I'm pretty damn sure, that I did NOT forget any typespecifiers, and nor did I forget to put Include Guards in my header files. |
- C2976: too few type arguments
I'm using a std::vector in a few places, and, NO, I did NOT forget the template-argument. I just don't understand why I get this error. |
- C2661: no overloaded function takes number parameters
Again - The compiler tells me that I don't put the right number of arguments in my functions, but unfortunately for me, I did. |
- C2504: base class undefined
So, I get this error in some (If not all) of my base-classes. And no, I did not forget to include the superclass-header, nor did I forget to put the class-definition in the superclass-header. |
- C2143: missing ';' before '*'
I got some functions returning a pointer to another one of my objects. I did include that object though, but the compiler does not seem to recognise it. A "real" syntax-error is completely impossible, in my opinion. Or maybe I'm just stupid. |
- C2065: undeclared identifier
Apparently the compiler doesnt recognise the class I'm using. Even if I did include it... Again. |
- C2061: identifier 'identifier' ("World" in my case)
NO, I did NOT mistype my classname. And I DID include it. |
- C2059: syntax error : '>'
Getting this on my vector-declaration. No clue why, of course. |
Those errors are driving me crazy, mainly because they make no freaking sense. If the compiler would tell me "Yeah you missed that include here, bro" it would be so much easier, but telling me "syntax-error" for something completely "else"? TL;DR I hate that compiler.
Finally I'll post a bit of code. I'll try to keep it short and readable, but since the errors are only in the headerfiles anyway that shouldnt be that much of a problem (Not posting all errors of course, just one file illustrating every problem. Since I got like at least 10x the same error.)
---- WORLD.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
|
#ifndef World_H
#define World_H
#include "Entity.h"
#include "BallEntity.h"
#include <Box2D/Box2D.h>
#include <SFML\Graphics.hpp>
#include <wink\slot.hpp>
#include <wink\event_queue.hpp>
#include <map>
#include "Event.h"
#include "CollisionEvent.h"
#include "WallEntity.h"
#include "Assets.h"
#include <stdlib.h>
class World : public b2ContactListener {
private:
std::vector<Entity*> entities;
sf::RenderTarget * target;
//std::map<unsigned short int, wink::signal<wink::slot<Event>>> eventSenders;
public:
b2World physicsWorld;
World();
void deleteEntity(Entity * entityToRemove);
void createBall();
void moveEntity(float delta, sf::Vector2f velocity, Entity * entity);
void update(sf::Time delta);
void render();
void BeginContact(b2Contact* contact);
void EndContact(b2Contact* contact);
};
#endif
|
Here, the errors are on the line
std::vector<Entity*> entities;
Errors here are: C2059, C2065, C2976, C2061(on multiple of the function declarations)
-----------------
--- ENTITY: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 57 58 59 60 61 62 63 64 65
|
#ifndef Entity_H
#define Entity_H
#include "World.h"
#include "Body.h"
#include <SFML\Graphics.hpp>
#include <Box2D/Box2D.h>
/**
Abstract entity-class.
*/
class Entity {
public:
/**
Entity-Constructor. Only called by subclasses.
@param RenderTarget Class used to draw Entities. (SFML specific).
*/
Entity(World * world, sf::RenderTarget* target);
/**
Destructor, inherited and defined by subclasses.
*/
virtual ~Entity() = 0;
/**
Returns the Body for this Entity.
*/
Body* getPhysicsBody();
/**
Returns the World in which the Entity is contained.
*/
World* getWorld();
/**
Creates the Body for this Entity.
*/
virtual Body* createBody() = 0;
/**
Method used to render the entity. Defined by subclasses.
*/
virtual void render() = 0;
/**
Method called every tick to update the entity. In most cases unsused.
*/
virtual void update(float delta) = 0;
/**
Get type of entity.
*/
virtual unsigned short int getType();
protected:
sf::RenderTarget* target;
Body * body;
World * parent;
};
#endif
|
Got C2061 errors with "World" identifier, and C2143 ";" before "*" errors. And of course C4430 errors a bit everywhere.
----------------
In those two classes nearly all errors are represented. As I said, I can't wrap my head around why it shows me those weird errors.
Would be really awesome if someone could help me (, before I destroy my computer in a burning fit of rage) =)
Kind regards