Loose Ends.

This is a discussion on Loose Ends. within the C++ Programming forums, part of the General Programming Boards category; Ok so I have design and written up my inventory for my game using vectors, I have created various other ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128

    Loose Ends.

    Ok so I have design and written up my inventory for my game using vectors, I have created various other bits n bobs, the part that has hindered me the most is how to go about structuring the moving between my areas.

    I had a thread on this, and now I know how the moving works, I just need a bit of correction on the way I should integrate this into my game structure.

    I know the way I have done it is not desireable but Im no pro at the moment.

    My basic plan is to split my 3 stories into 3 functions, which are split into 3 files.

    Now this compiles and runs the way it is except it does not execute the void storyone() function. It just skips it and ends the program.

    Maybe something to do with putting it in a header file, but I was told it is bad to include .cpp files are they are compiled separately.

    Note: this is mostly group of examples I have put together to help with my understanding so its very rough.

    main.cpp
    Code:
        cout << "Easy,Normal or Hard. \n1\t2\t3\n\n";
        int iTempDifficulty;
        cin >> iTempDifficulty;
            do {                                                                                                                  // Do While -
    
            if (iTempDifficulty == 1) {                                                                                       // Set Case If
                iGlobalLevelChoice = 1;
            }
            else if (iTempDifficulty == 2) {                                                                                  // Set Case If
                iGlobalLevelChoice = 2;
            }
            else if (iTempDifficulty == 3) {                                                                             // Set Case If
                iGlobalLevelChoice = 3;
            }
            else {                                                                                                            // If none above then do
                cout << "Invalid selection! \nPlease choose a level,\n\n EASY \t Normal \n HARD \n\n";
            }
        } while (iGlobalLevelChoice == 0);
    
    
        cout << "\nNow that we are all set up; let the game begin.................................. \n\n";
    
        cout << "\n\n";
    
        void storyone();
    story1.h
    Code:
    void storyone()
    
     {  bla bla bla ......
    }
    Attached Files Attached Files

  2. #2
    pwning noobs Zlatko's Avatar
    Join Date
    Jun 2009
    Location
    The Great White North
    Posts
    132
    Aliaks, you need to remove the void from the call to storyone(). The compiler treats what you have as a function declaration.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    To call a function, you type its name, and the name of any parameters you want to pass between the ( and ), separated by a comma (,).
    Do NOT type the return type of the function. Then it's interpreted as a declaration.
    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. #4
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    So thats why none of my others worked either! Thanks for clearing that up

    And it is fine to have each story in a function which is in a header?


    It just came back with this as an debug error but this file is included into the header file :S

    Code:
     void User::vSetUserName(string sUsername)
    {
        m_sUsername = sUsername;             //Store the contents of sUsername in m_sUsername
    }
    Both the iTempAge and the sTempUserName are externs and there is no name mis match :S
    Last edited by Aliaks; 07-14-2009 at 11:27 PM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    Don't put implementations in headers. Implementations is the code you fill the functions with.
    Put the function prototypes in the header and the implementations in the source files.
    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. #6
    Registered User
    Join Date
    Jun 2009
    Location
    Adeliade, AU
    Posts
    128
    the code I postred above is in a .cpp file

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,014
    It was in response to this:
    Quote Originally Posted by Aliaks View Post
    And it is fine to have each story in a function which is in a header?
    Also, do NOT include .cpp files, if you did that. They are compiled separately.

    The class implementation source file must include the header that contains the class declaration for the class it's implementing. In your case, classes.h.
    It's also a good idea to split each class into its own file to make it better organized.

    And finally, you need to read this: Do not remove parameter names (click me!)
    Last edited by Elysia; 07-16-2009 at 03:07 AM.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to cap the gluCylinder() ends
    By ting in forum Game Programming
    Replies: 1
    Last Post: 06-02-2008, 06:03 PM
  2. Socket abruptly closes after function ends
    By Sfpiano in forum Networking/Device Communication
    Replies: 1
    Last Post: 08-08-2005, 05:49 PM
  3. Laptop Lid Loose (Toshiba Tecra)
    By moonwalker in forum Tech Board
    Replies: 0
    Last Post: 07-14-2003, 10:11 PM
  4. Why do i loose my first character?
    By ss3x in forum C++ Programming
    Replies: 4
    Last Post: 04-10-2002, 04:04 PM
  5. Some loose ends
    By pdstatha in forum C Programming
    Replies: 7
    Last Post: 03-31-2002, 04:03 PM

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