Help with NULL arguments

This is a discussion on Help with NULL arguments within the C++ Programming forums, part of the General Programming Boards category; I'm having trouble with sending NULL as an argument for a pointer. The functions and calls are as follows: Code: ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105

    Help with NULL arguments

    I'm having trouble with sending NULL as an argument for a pointer. The functions and calls are as follows:

    Code:
    void room::build_connections(room* uparg, room* downarg, room* northarg, room* southarg, room* eastarg, room* westarg, room* currarg)
    {
         to_up=uparg;
         to_down=downarg;
         to_north=northarg;
         to_south=southarg;
         to_east=eastarg;
         to_west=westarg;
         currroom=currarg;
         
         if (to_up != NULL) up_exist=true;
         else up_exist=false;
         if (to_down != NULL) down_exist=true;
         else down_exist=false;
         if (to_north != NULL) north_exist=true;
         else north_exist=false;
         if (to_south != NULL) south_exist=true;
         else south_exist=false;
         if (to_east != NULL) east_exist=true;
         else east_exist=false;
         if (to_west != NULL) west_exist=true;
         else west_exist=false;
    }
    Code:
    room room1("Sup", "Heya", "Wat");
    room room2("Desu", "Da ne", "Nyoron~");
        
    room1.build_connections(NULL, NULL, room2, NULL, NULL, NULL, room1);
    room2.build_connections(NULL, NULL, NULL, room1, NULL, NULL, room2);
    Hatman Approves!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What exactly are you having trouble with?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Oh, right, forgot to post the error message I got.

    In function `int main()':
    no matching function for call to `room::build_connections(NULL, NULL, room&, NULL, NULL, NULL, room&)'
    candidates are: void room::build_connections(room*, room*, room*, room*, room*, room*, room*)
    no matching function for call to `room::build_connections(NULL, NULL, NULL, room&, NULL, NULL, room&)'
    candidates are: void room::build_connections(room*, room*, room*, room*, room*, room*, room*)
    Hatman Approves!

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Removed for idiocy. Sorry.
    Last edited by tabstop; 07-06-2009 at 04:37 PM.

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    NULL is a null pointer literal. It can be any pointer type. As long as you don't have ambiguous overloads, there's no problem.

    The problem isn't NULL. The problem is that you're trying to pass the rooms by value when you're supposed to pass a pointer to them, i.e. it should be
    Code:
    room1.build_connections(NULL, NULL, &room2, NULL, NULL, NULL, &room1);
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Nov 2007
    Location
    Free Country, USA
    Posts
    105
    Thanks! It works now. I probably should have thought of that before.
    Hatman Approves!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling 3rd party code problem me too
    By siavoshkc in forum C Programming
    Replies: 1
    Last Post: 09-12-2007, 05:55 AM
  2. Tweakable Radar...
    By DoraTehExploda in forum Game Programming
    Replies: 8
    Last Post: 06-07-2005, 10:49 AM
  3. . . . . . . - . . . - -
    By The Brain in forum C++ Programming
    Replies: 17
    Last Post: 05-17-2005, 04:01 AM
  4. Really Need Help With My Opengl Camera!!!!
    By psychopath in forum Game Programming
    Replies: 13
    Last Post: 05-28-2004, 03:05 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21