Advertisement

help with classes

Started by May 09, 2001 04:11 PM
3 comments, last by capn_midnight 23 years, 9 months ago
got a problem with my class:
  
#define AREA_HEIGHT 10


class room_c{
private:
   string descrip;
   int exits[8];
public:
   room_c();
   void view();

//and here is the problem

   friend int init(room_c[][AREA_HEIGHT]);
};

int init(room_c[][AREA_HEIGHT]);
  
Basically, int init() reads from a file all of the room descriptions and stores them in an array that is passed as a reference parameter. init() returns 1 if succesful. I get the error "room_c is not a defined structure" at that point. I understand why it is coming up, what can I do to get rid of it or work around it? init has to be able to access descrip and it has to work on a whole array, instead of just one at a time. Should I just make descrip public and forget about it? AOL, so easy to use, no wonder it''s nothing but a bunch of retards Spyder''s Web Games

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This is wierd, since under the VC help it shows an example where a friend function declared in a class takes a parameter of that class.

Edited by - Zipster on May 9, 2001 10:48:21 PM
Advertisement
A class (or struct) can''t have one of it''s members another of itself.

Imagine struct blah{
int x;
int y;
struct blah nextBlah; };

If you create one blah:

blah myBlah;

it''s members are x, y, and nextBlah; nextBlah''s members are also x, y, and nextBlah; and that nextBlah''s members likewise are x, y.....

If you want an object or parameter within a class to be of that type, you need to make it a pointer.
I cut and pasted your code and it compiled and linked with no errors using VC6/SP5. Maybe, as a workaround for whatever compiler you''re using, you could just pass a room_c* to init and handle the math for 2D array access yourself?
oh brother. just great. Well, I figured I needed to upgrade to a new compiler anyway. I''m using Borland C++ 4.52. I''ll have to see if I can still get VC++6 for free from campus.

As to this pointer idea, is it a NULL pointer and then I figure out the location of the different elements based on data type memory size? So if the first two elements of my class were two integers, and the pointer to the class was *pntr, then the first int would be at *pntr and the second int would be *(pntr+sizeof(int))? but how would I reference anything after a string (of undefined size)? Or how would I reference a member function?

Aw forget it. I''ll just make everything public and still use most of the object oriented features. Maybe later if I figure it out I''ll change them back to private.

AOL, so easy to use, no wonder it''s nothing but a bunch of retards

Spyder''s Web Games

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement