It's right there!

Started by
10 comments, last by Zakwayda 16 years ago
Right, not entirely sure what's going on with this. I can't work out why my Object and Zone classes are unable to find the Polygon class (despite it being there above them) when the Object class is picked up fine by the Zone class. The code;

struct Vector
{
    float x,y,z;
};

class Vertex
{
    Vector position,normal;
};

class Material//contains a diffuse(texture)map,a normal(bump)map, a specular map, and a sound effect for objects moving across it
{
    Texture *diffuse,*normal,*specular;
};

class Polygon
{
        Vertex* index_list;
        size_t  num_indices;
        Material* material;
};

class Object
{
        Polygon*    polygon_list;
        Object*     children;
        size_t      num_polys,num_children;
};

class Zone
{
        Object* object_list;
        Polygon* polygon_list;
        size_t num_objects,num_tris;

    public:

        void AddObject(Object*,size_t);
        void RemoveObject(Object*);
};

class Level
{
        Zone*       zone_list;
        Material*   material_list;
        size_t      num_zones,num_materials;

     public:

        void LoadLevel();
};
and the errors;

level.h:28: error: ISO C++ forbids declaration of `Polygon' with no type // <-Object
level.h:28: error: expected `;' before '*' token
level.h:36: error: ISO C++ forbids declaration of `Polygon' with no type // <-Zone
level.h:36: error: expected `;' before '*' token

I've tried deleting the object files(not suprisingly didn't do anything, as this is in a header), removing and re-adding the file to the project, and resetting the computer, but I'm out of ideas. Is it just a coding problem that's glaringly obvious to others, or am I justified in being stumped? Oh, and before I forget, Texture is defined in another header, linked in before this one.
Advertisement
I would try renaming it, just to see if it works. Like to TmpClass.
The code you posted compiles just fine in VC++ 2005, provided I add a dummy Texture declaration at the top. The problem must be related to code somewhere else, I guess.
It seems there is a variable called Polygon somewhere else. Renaming the class seems to do the trick. Cheers to both of you.
Quote:Original post by webwraith
It seems there is a variable called Polygon somewhere else.

This would not have happened with strict coding conventions (variables start with a lowercase letter, types with an uppercase letter).
Aiyayayayaya. Don't do this:

class Thingy {  Subthingy* subthingies; // will point to a new Subthingy[] array  int num_subthingies;};// Lots of code somewhere else that manages the memory


Do this:

class Thingy {  std::vector<Subthingy> subthingies; // the standard library loves you};// The "num_subthingies" is always available as subthingies.size()// and you will never have to worry about the pointer being uninitialized or NULL.
#DevFred: What are you talking about, I'm defining the class name as Polygon, not instantiating an object, which is exactly what you seem to be getting on at me for NOT doing. If it makes you feel any better, I always use the convention you have decided is best for yourself. At least we should be able to read each others code.

#Zahlman: In case you didn't notice it, there is a class with name "Vector" in my code, already. Now I know the STL and CSL vectors are both lower case, but a single difference is too close for me. Besides as long as I'm careful, there is no reason why the "pointer and max count" method won't work. It was used all the time back in C, after all...


...it's also probably the way the std::vector takes care of things under the hood, anyway...
Except std::vector will do it right for you. With your method you will have to spend time and effort making sure you do it right instead. This includes managing allocation and destruction, resizing, validity and aliasing, et cetera.

std::vector is the safe, idiomatic C++ method of handling dynamic (relative to compile time -- which yours is, even if max size stays fixed at runtime) arrays in C++. Learn to use it, and you become a better C++ programmer.

Or don't, and insist on being a C programmer in a language that is not C, with all the disadvantages and productivity hurdles that entails.
Quote:In case you didn't notice it, there is a class with name "Vector" in my code, already. Now I know the STL and CSL vectors are both lower case, but a single difference is too close for me.
Don't let the names of the SC++L classes discourage you from using them. They're all safely wrapped in the std namespace, so unless you're doing something unwise, you shouldn't have any collisions.
Quote:Besides as long as I'm careful, there is no reason why the "pointer and max count" method won't work. It was used all the time back in C, after all...
But why make things harder for yourself than necessary?
Quote:Original post by webwraith

Besides as long as I'm careful, there is no reason why the "pointer and max count" method won't work. It was used all the time back in C, after all...


Why are you using such verbose syntax....

#define class C#define size_t INT#define float REALC VCTR { REAL X,Y,Z; }C VRTX { VCTR POS,NML; }C MTRL { TXTR *DFS,*NML,*SPL; }C PLGN { VTX *IDX; INT NMI; MTRL MTR1; }C OBJ  { PLGN PLLS; OBJ * CHLD; INT NMPL,NMCL; }C ZONE { OBJ *OBLS; PLGN *PLLS; INT NMOB,NMTR;   void AOBJ(OBJ*,INT);  void ROBJ(OBJ*);}C LEVL { ZONE *ZNLS; MTRL *MTLS; INT NMZN,NMMT;   void LLVL();}


What?

It worked in BASIC, and Fortran before then. And if you're careful, you won't confuse MTRL and MTR1, or run into name conflicts.

Use what was proven 40 years ago to work and work well. Stand on the shoulders of giants. And don't make me bring out punch card reader....

This topic is closed to new replies.

Advertisement