Thread: Errors with redefining objects

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    106

    Errors with redefining objects

    Or, rather, pointers, in this case.

    http://www.dragonnetworks.net/users/suzaku/source_code/

    Everything's there.

    Anyway, the pointer to an object in this case is room *current_room, which is declared in the globalObs.h which I don't have uploaded. It's the only thing in globablObs.h, though, so yeah.

    Basically, when compiling the .os', everything seems to work. On linking, though, I get an error which basically says that, in main_loop.cpp, I'm redifing current_room, which is first defined in classes.cpp. I'm guessing I'm either misusing pointers or preprocessor directives here.

  2. #2
    Registered User Sake's Avatar
    Join Date
    Jan 2005
    Posts
    89
    I would wager that you're making two mistakes. First, you aren't putting inclusion guards on your headers. They look like this.
    Code:
    #ifndef SOME_UNIQUE_SYMBOL
    #define SOME_UNIQUE_SYMBOL
    
    // Everything for the header here
    
    #endif
    Second, you have a definition in one of your headers. You should avoid that by only placing declarations in the header file and then defining those names in a source file.
    Code:
    // globals.h
    extern room *current_room;
    Code:
    // globals.cpp
    room *current_room = 0;
    Include globals.h everywhere you need current_room, then compile and link with globals.cpp as you would any other source file. I could be wrong in what your problem is, but following those two guidelines will save you headaches later even if it isn't your current problem.
    Kampai!

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    Ah, that did it. Thanks a lot. I'd had preprocessor code in at one point. I guess it was that extern and defining it outside of the header that was the big issue. Thanks, though.

    I've got a new, interesting problem now. In int main(),

    hall1.on_init("Hall 1", &hall1, &hall3, &hall2, &hall1);

    is giving me a

    main_loop.cpp request for member `on_init' in `hall1', which is of non-aggregate type `room ()()'

    error. From what I've seen so far, I'd typically get errors like this if I hadn't probably set pointer operator thingies. Such as, if I had a *object, I'd have to use object->member to do stuff instead of object.member. hall1 is not a pointer though, and changing the period to a -> anyway doesn't seem to help. This, of course, leaves me at a loss. I guess I'm probably breaking something in the function definition.

    Code:
         void room::on_init(string desc, room north, room south, room east, room west)
         {
              room_desc = desc;
              at_north = &north;
              at_south = &south;
              at_west = &west;
              at_east = &east;
         }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  2. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  3. Linker errors in VC++ 2005
    By C+/- in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2007, 07:42 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM