seemingly nonsensical syntactical error, polymormphism maybe?? please help!

sorry again, this isn’t really opengl related. i’m trying to pull together a raytracer, but i have this problem. i have a class that is a root class for a lot of other classes.
for instance in this code:


…int recurseLevel;
int row, col; // for screen extents
int numInside; // number of objects on list
GeomObj* inside[10]; // array of object pointers

Ray();.........

i get these errors and more all over:

\mesh.h(46) : error C2143: syntax error : missing ‘;’ before ‘*’

mesh.h(46) : error C2501: ‘GeomObj’ : missing storage-class or type specifiers

now obviously the GeomObj class is not getting recognized as a type specifier
this is the declaration and definition of the class:


//@@@@@@@@@@@@@@@@@@@@@ GeomObj class @@@@@@@@@@@@@@@@
class GeomObj{
public:
IntRect scrnExtnt;
Cuboid genBoxExtent,worldBoxExtent;
SphereInfo genSphereExtent,worldSphereExtent;
GeomObj * next;
GeomObj(): next(NULL){}
virtual bool hit(Ray &r, Intersection &inter);
virtual void loadStuff();
virtual void drawOpenGL();
virtual void tellMaterialsGL();
virtual void makeExtentPoints(PointCluster& clust);
virtual Point2 texturePoint(Point3 p);
virtual Color3 texture(HitInfo& h);
};

//@@@@@@@@@@@@@@@@@@@@@ GeomObj class @@@@@@@@@@@@@@@@

bool GeomObj::hit(Ray &r, Intersection &inter){return false;} //virtual
void GeomObj::loadStuff(){return;} //virtual
void GeomObj::drawOpenGL(){return;} //virtual
void GeomObj::tellMaterialsGL(){return;} //virtual
void GeomObj::makeExtentPoints(PointCluster& clust) //virtual
{cout << “in makeExtentPoints for GeomObj”;}
Point2 GeomObj::texturePoint(Point3 p){Point2 pt(0,0); return pt;}
Color3 GeomObj::texture(HitInfo& h){Color3 c(0,0,0); return c;}


ok and if i type in for instance “GeomObj::” into MSvisualC++ i get a list of all the class functions and members… all of my other classes work.

there is one line in this i don’t understand but i got it from a textbook it is:

GeomObj(): next(NULL){}

in the declaration. i can’t find info on this type of code anywhere.

but i think most likely there is a very stupid reason it is not taking. as it usually always is. sorry to be a pain. if any one would let me email the source code to them to sort it out it would be my pleasure to do so. everything is 140kb uncompressed. thank you for your time and consideration.
sincerely,

Michael

Hi !

just from your excerpts, it seems that your code :

int recurseLevel;
int row, col; // for screen extents
int numInside; // number of objects on list
GeomObj* inside[10]; // array of object pointers

Ray();…

misses an include file. Try to replace the line with this:

class GeomObj* inside[10]; // array of object pointers

The thing you don’t understand :

GeomObj(): next(NULL){}

is a member initialization. This can be used in constructors to initialize member variables, it is especially helpful to avoid a default construction and an assignment, or mandatory to construct reference members…

Hope this helps! I strongly suggest you to grab some kind of C++ handbook before diving! It could help

just from your excerpts, it seems that your code :

                            code:


                            int recurseLevel;
                            int row, col; // for screen extents
                            int numInside; // number of objects on list
                            GeomObj* inside[10]; // array of object pointers
                            Ray();.........

" misses an include file. Try to replace the line with this:

                            code:


                            class GeomObj* inside[10]; // array of object pointers"

well the header where the GeomObj class is defined is #included. in the part of the code a pointer to an array of GeomObj(s) called inside is being declared i believe. i just pulled out that excerpt arbitrarilly because it was the first compile time error involving GeomObj. i have like 35 classes and 15 files in my workspace working ok. i like to think i know someting about coding. this is really bugging me. i will try using “class” before it but i’ve never seen that used. i suppose it is used for extra clarity. just tell me if my declarations and definitions are straight please so i can think to look somewhere else.

                      " Hope this helps! I strongly suggest you to grab some kind of C++ handbook before diving! It could help "

I’ve read clear through a c++ and computer graphics textbooks a few times. but i can’t very well find info on a particular construct if it only consists of a colon and nothing in particular to distinguish it. try looking up a colon in the help docs or an index. or try asking a bbs full of competent coders… you make the call

also the GeomObj class doesn’t work all over the work space. its really bugging me. i’ll give it another go tonight. i just want to declare a GeomObj and have the compiler recognize it as such like believe it or not i’ve probably done hundreds of times. thats why its bugging me becuase it makes absolutely no sense. but their is always a logical solution. thanks so much for the insight.

Michael
[/b][/QUOTE]

[This message has been edited by wildeyedboyfromfreecloud (edited 01-05-2002).]

Hey! i just got home and typed in class once like you said and bingo 40 something errors gone. it seemed to work but i don’t understand why. is there no way i can do it without typeing class? anyhow thanks alot. i really apreciate it as usual

Michael

Originally posted by wildeyedboyfromfreecloud:
Hey! i just got home and typed in class once like you said and bingo 40 something errors gone. it seemed to work but i don’t understand why. is there no way i can do it without typeing class?

The problem with your code is that the compiler doesn’t know what a GeomObj is. I’m assuming you have a header file somewhere that describes the GeomObj class. Dollars to doughnuts that header file is not being #include’d.

Adding the word ‘class’ before the type name tells the compiler that GeomObj is a class. The compiler doesn’t know what your class does, but it has enough information to create an array of pointers to your class, so it doesn’t complain.

You’d get an error if you tried to use the class, however. Withouth the #include, the compiler won’t know how to construct or call methods of the class.

Every .cp file that uses GeomObj should #include the file that declares GeomObj. (“GeomObj.h” ?)

thats what i thought. but it is #include’d. i better check it out and see if i can’t resolve it. then i will get back here if i can’t straighten it out. thanks alot. i was afraid of that.

no luck. would it matter if one class need the other class to be defined in its definition. while the other class needed the former class in its declaration as well. so in other words both classes need each other to function. but one comes before the other. now would the “extra class” declarative be needed then so that the compiler allocates room for it and then moves on and fills it in after it finds the declaration of the second class, then relaying that back to the other class??? i hope any of that made sense. that is all that i can think of to explain this. please let me know.

i’ve tried for too long. i can’t get it to compile without using the extra class declaration. is there any instance where this methodology would be necesarry? this is so weird. everything is defined and declared and #included par usual. also what is the likelyhood that it is actually compiled properly. as i haven’t got to implementing the code. damn school tomorrow i better get to that. thanks so much for all the advice. i apreciate it so much.

Firstly, you must define the class in the header then include it - alternatively, you can put the code ahead of the declarations you use in your .cpp file.

Like this:

class B; // tell compiler we will reference this class

class A {

A {}
~ A {}

B MyB; // declare MyB to be of class `B’
};

class B {

B {}
~ B {}

A MyA; // Circular, we use an A in a B.

};

thanks everyone for being helpful. but you don’t have to be insulting. just kidding i really apreaciate. For Robo, the problem was that the classes each referenced each other. i’m still not sure that the code is air tight. but it all seems to work. much thanks anyway.

Michael

Fen

[This message has been edited by wildeyedboyfromfreecloud (edited 01-08-2002).]