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

Pages: 1-

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-24 18:31

I feel I should add that all three of those errors are for line 10 of edge.h, in case that wasn't obvious.

Name: Anonymous 2009-04-24 18:34

let x=y; y=x in putStrLn $ "OP is a " ++ x

Name: Anonymous 2009-04-24 18:43

You have a circular reference by value -- Edge HAS A vertex; Vertex HAS A Edge.  Fortunately Sepples is too brain-dead to realise the full horror of this recursion (infinite size structures).  You have to break the loop of knowing how big each instance is:

#ifndef Vertex_h
#define Vertex_h

class Edge; // forward reference

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

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

#endif


and

#ifndef Edge_h
#define Edge_h

class Vertex; // forward reference

class Edge
{
public:
    int label;
    Vertex * v;

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

#endif

Name: Anonymous 2009-04-24 18:46

If every Vertex structure contains an Edge, and every Edge contains a Vertex, what is sizeof(Vertex)?

Name: Anonymous 2009-04-24 18:50

I see.  Thanks guys.

Name: Anonymous 2009-04-24 19:26

>>4-5
This would be much better suited to a relational data structure: create Edge_Vertex which connects the two.

Name: Anonymous 2009-04-25 3:18

>>7
Adding an extra level of indirection is usually good, but you can still get OP's loop via

Edge HAS A Edge_Vertex HAS A Vertex HAS A Edge_Vertex HAS A Edge...

if you continue to naively include by value.

Name: Anonymous 2009-04-25 4:22

Adding an extra level of indirection is usually good,
this is how sepples programmers actually think. yes, really.
because obfuscated code is GREAT!

Name: Anonymous 2009-04-25 7:36

>>8
Learn SQL.

Name: Anonymous 2009-04-25 9:24

>>9
indirection != obfuscation

Name: Anonymous 2009-04-25 9:25

>>11
indirection ⊂ obfuscation

Name: Anonymous 2009-04-25 9:46

indirection ∈ obfuscation

Name: Anonymous 2009-04-25 10:08

"Any problem in computing can be solved by adding another level of indirection."
David Wheeler, according to Roger Needham, according to Butler Lampson et al.

Name: Anonymous 2009-04-25 10:15

>>5
Mu.

Name: Anonymous 2009-04-25 11:05

Edge and vertex are so closely related that each has a reference to the other yet you put them into different headers? Good luck with your project, say hi to bjarne for me.

Name: Anonymous 2009-04-25 11:11

>>1
cout << "It works." << endl; //lol, no.
Is that comment relevant?

Name: Anonymous 2009-04-25 11:25

>>16
say hi to bjarne for me.
What is ``bjarne'' and how could you say hi to it if it is not a unique entity?

Name: Anonymous 2009-04-25 11:25

or just you're way of saying "IVE READ SICP"

Name: Anonymous 2009-04-25 12:10

>>18
RFEAQGUGIORTE SQ UFOETWEESR

Version 2.0, released under the Creative Commons License.

Name: Anonymous 2009-04-25 12:47

>>20
the
I don't think you understand licenses.

Name: Anonymous 2009-04-25 13:21

>>21
Version 2.0, released under the Noncommercial Creative Commons License.

Name: Anonymous 2009-04-25 19:15

>>1
goddammit, C++
>>1-san is a perfect example of the average faggot who blames languages for his ineptitude and not himself.

Learn to code. Seriously.

Name: Anonymous 2009-04-25 19:20

>>23
“I liken starting one’s computing career with C++, say as an undergraduate,
to being born in East Africa. It is intolerably hot, your
body is covered with lice and flies, you are malnourished and you
suffer from numerous curable diseases. But, as far as young East
Africans can tell, this is simply the natural condition and they live
within it. By the time they find out differently, it is too late. They
already think that the writing of C++ is a natural act.” - Ken Pier, Xerox PARC

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?

Name: Anonymous 2009-04-25 20:54

>>25
Think of it this way: it's kind of like rain on you're wedding day

Name: Anonymous 2009-04-25 20:57

ITS like HAXING on your ANUS day

Name: Trollbot9000 2009-07-01 8:41


Im or blackmail you.

Name: Anonymous 2010-12-09 2:32

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