Moving between areas

This is a discussion on Moving between areas within the C++ Programming forums, part of the General Programming Boards category; No, it's code, thus should be inside a function, and function implementations should be inside .cpp files. But you can ...

  1. #46
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    No, it's code, thus should be inside a function, and function implementations should be inside .cpp files.
    But you can put those into a separate .cpp file if you believe it helps.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #47
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ok then, how about

    Code:
    Room *location;
    I would like to move this into my classes.h like this

    Code:
    class User
    
    {
    
    public:
    
        void vSetUserName(string);         //Function for setting the username, takes a string
        void vSetAge(int);                      //Function for setting the age, takes an int
    
        string sGetUserName() const;       //Function for retrieving the username
        int iGetAge() const;                    //Function for retrieving the age
    
        Room *location;
    but it says it is expecting a ; before * when I move it to my classes.h

  3. #48
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Did you include proper header file for Room before?
    If yes, then I would check to see if User class header includes another header which includes the user class header again. That can cause all sorts of problems.

    And just as a FYI, you can also type Room *location as Room* location.
    You know a little of pointers, I hope?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #49
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Yeah I know the basics of most the topics I just have come across some more indepth stuff which I havnt come across yet so its taking a bitl onger to process.

    main.cpp includes classes.h

    storyone.cpp includes classes.h

    pets.cpp includes classes.h

    user.cpp includes classes.h

    Will that be the problem?

    and yeah I knew you could do that

  5. #50
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    The .cpp files includes are not a problem. But what about the includes of the headers themselves?
    They may have circular dependencies, unless you actually forgot to include the proper header that declares the class Room.
    And because I loves FYIs, here's another one
    Stroustrup: C++ Style and Technique FAQ
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #51
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ha, I think I have fixed it.

    I had the Room class AFTER the Player Class so I think the room *location practically didnt mean anything

  7. #52
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Is there anyway to make a class kind of... global? lol.

    I want to have a cpp file with a single function in it called storyone.cpp

    but I cant compile it because it is saying NewUser (Which is a defined class) isnt declared within this scope.

  8. #53
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Yes, it is possible to make global variables, but you should be careful with them.
    Put the variable inside ONE .cpp file, ie: int x = 55;
    Then put the same declaration inside a header file with extern before: extern int x;

    As long as you include header, it will compile.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #54
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Ahh I see. Thats clever. Why the careful ness? is it dangerous?

    and does that one variable inside the .cpp file have to be global? or can it be within a function ?

  10. #55
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    Because it's difficult to know when a global variable was changed, making it difficult to debug and maintain code.
    It's also more difficult to know where a global variable is located.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #56
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    Can I also do it with a class? Like I have the class made in my main as the user enters his name etc and then access the class for the movement within another file?

    Or should i take the names of the user put it into a global variable and define the user in the other file

  12. #57
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    Quote Originally Posted by Aliaks View Post
    Can I also do it with a class? Like I have the class made in my main as the user enters his name etc and then access the class for the movement within another file?

    Or should i take the names of the user put it into a global variable and define the user in the other file
    That would most likely be a Player class. No need for globals just pass relevant variables as references.

  13. #58
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    P:\KOA_DM_IT\KOA_DM_IT\story1.h|69|error: `NewUserlocation' was not declared in this scope|

    Which is this line

    Code:
     NewUser.location = NewUserlocation->north;
    but I have this..

    Code:
     NewUser.location = &rooms[0];
    Last edited by Aliaks; 07-14-2009 at 06:36 AM.

  14. #59
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,031
    We cannot guess where NewUserlocation is declared and defined...
    But obviously it wasn't defined in the function you needed to use it in.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #60
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    But surely this should be it

    Code:
    NewUser.location = &rooms[0];
    which I have in the function

Page 4 of 7 FirstFirst 1234567 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack overflow errors in 3 areas
    By ulillillia in forum C Programming
    Replies: 13
    Last Post: 04-29-2007, 04:20 PM
  2. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-24-2007, 12:05 AM
  3. rescaling areas
    By hannibar in forum C Programming
    Replies: 2
    Last Post: 02-28-2006, 03:22 PM
  4. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 05:46 AM
  5. Simple program i cant get (dot moving)
    By Lupusk9 in forum C++ Programming
    Replies: 4
    Last Post: 09-14-2004, 09:04 PM

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