Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

goddammit, C++

Name: Anonymous 2009-04-24 18:28

Hey, /prog/.  I have encountered a frustrating problem in my project.  I've stripped my code down to the bare essentials and I still don't know why this is fucking up.

main.cpp:


#include <iostream>
#include "vertex.h"
#include "edge.h"
using namespace std;

int main()
{
    Vertex v;
    Edge e;
    cout << "It works." << endl; //lol, no.
}


edge.h:


#ifndef Edge_h
#define Edge_h

#include "vertex.h"

class Edge
{
public:
    int label;
    Vertex v; // This line does not compile.  edge.h does not know what a vertex is.

    Edge() : label(1) {}
};

#endif


vertex.h:


#ifndef Vertex_h
#define Vertex_h

#include "edge.h"

class Vertex
{
public:
    int label;
    Edge e;  // This line compiles just fine.  vertex.h knows what an Edge is.

    Vertex() : label(1) {}
};

#endif


Errors:
Error    1    error C2146: syntax error : missing ';' before identifier 'v'
Error    2    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error    3    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   

So, can anyone tell me what ridiculously stupid thing I'm doing and/or ridiculously simple thing I'm missing?  This is driving me nuts.

Name: Anonymous 2009-04-25 19:36

>>24
He included one header in another header, and in that other header, he included the first header also. In both of these classes, he tried to use the other class.

Are you kidding me? Do you seriously think it's not the programmer's fault?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List