My (mostly technical) blog

Archive for December 30th, 2006

Ever since I started programming with C++, I have been pulling my hair out trying to decrypt what the compiler errors mean.

Coming from the Java camp, I just hate how C++ compilers work and how stupid they are! After spending 3 hours trying to know why this piece of code won’t compile, I found out the answer after searching for a LONG time.

The code:

#pragma once
#include “Edge.h”
#include “IDGenerator.h”
class Face {
public:
Edge *edge;
int id;
Face(){
id = IDGenerator::getFaceID();
}

void setEdge(Edge *e) {
edge = e;
}
int getID() {
return id;
}

Edge *getEdge() {
return edge;
}
};

The compile error I was getting was:
error C2143: syntax error : missing ';' before '*'

it was choking at the “Edge *edge” line. To cut a long story short, if you are going to use a pointer to another class, don’t include the file as above, just use forward declaration by adding:

class Edge;

at the top of

class Face {

so that the final version looks like:

#pragma once
#include “IDGenerator.h”

class Edge;

class Face {
public:
Edge *edge;
int id;
Face(){
id = IDGenerator::getFaceID();
}

void setEdge(Edge *e) {
edge = e;
}
int getID() {
return id;
}

Edge *getEdge() {
return edge;
}
};

for a better explaination:
http://www-subatech.in2p3.fr/~photons/subatech/soft/carnac/CPP-INC-1.shtml

I finally have my own blog!

I have been intending to create one for a long time. I still don’t quite know what will I post here, but I will find something 🙂


Ahmed Sabbour's Facebook profile
December 2006
S M T W T F S
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Recently bookmarked