Thread: A little help with member functions

  1. #16
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    You include by using
    Code:
     #include "header.h"
    . Notice the " " instead of < >, the " " say to the linker, look in the same directory as the .cpp file you are compiling. < > says to look in the included folders that are set up. In general adding your own custom headers to your /include/ folder in any compiler is not the way to go.

  2. #17
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Thanks, I'll try that

  3. #18
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Well, I just tryed it and thanks! It makes multi file projects
    as easy as showing up drunk to your sister's wedding!

    On a completely unrealated topic, I used to think, to people
    that used printf(), "You dinosour, if you're not going to use cout
    and you're just going to do it the hard way, why don't you
    manualy compile your code too!"... But I have since realized why
    people use that garbage function that should be depricated,
    It takes up way less space. stdio.h takes up less than 0.4% of
    the space iostream takes up. iostream adds like 400kb to the exe
    while stdio.h adds only like 0.6kb. However, iostream, with it's
    nice cout and cin, are too much for me to give up.

    Wouldn't you rather do this:

    cout
    << "The program looped "
    << NumberOfLoops
    << " times.\n";

    than this:

    printf(The program looped %d", NumberOfLoops);
    printf(" times.");

    The answer is obvius.

  4. #19
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Another thing to consider, is while it is many times larger, .4meg is almost nothing now-a-days. If your ram was limited to 16meg I can see nitpicking, but most people have 256+ if they bought their computer in recent years.

  5. #20
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Hmmmmmm, Now I have another error! Now I made the class for player, and saved
    the file and when I looked at my class browser it wasn't there! If that had been all
    I probably wouldn't be writing this. Then I declared a player by the name of KILLER
    and when I tryed to access the variabes inside the class by typing KILLER and then a .
    it wouldn't pop the little list of members inside the class! And that can only mean that
    my compiler won't register the class and I can't use it. Please help.

  6. #21
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    first time using functions within classes.
    In reality though. You should take this project to learn how to use includes to include other source files that you are writing.
    Wrong.
    Well, I just tryed it and thanks! It makes multi file projects
    as easy as showing up drunk to your sister's wedding!
    I stand corrected. I guess the nightmarish memories of a 40+ post thread where I tried to help someone understand multi file projects are still too fresh.

    http://cboard.cprogramming.com/showt...multiple+files
    Last edited by 7stud; 02-23-2006 at 01:59 PM.

  7. #22
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Have you tried compiling? Just because your autofill things don't work doesn't mean the code is wrong, type it out by hand and try and compile, if you are used to it typing it out for you, double check your capitolization and spelling if you get an error.

  8. #23
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    I started to type it out an I got an error message. My compiler does that somethimes.
    It just picks a file and every time I do something in that file from then on it gives me a
    "list index out of bounds nnn" message. I know it will continue to do so. Now my
    class is messed up and my compiler is being a &^#*<. I would call this a bad day.
    And it was capitalized correctly earlier. and I'm totaly sure of that because I checked it,
    in addition it didn't show up in my class browser, which spells bad news. Okay it doesn't literaly spell bad news but you get the point. It's trying to kill me with meanness.

  9. #24
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Okay, I have an even worse problem. I tryed to compile and now it says that my variables
    that I declared as the classes I just wrote are "used as types but not defined as types"
    I fear I may have to dump 347 lines of code on you guys. One point of intrest is that the
    variables in question are declared inside classes.


    Code:
    class foo {
    public:
    
    void ShowFoo(void) {
    cout << "fofo";
    }
    
    };
    
    
    class SuperFoo {
    public:
    
    foo FooA;
    foo FooB;
    };

    I know this works because

    A: I have seen otehrs do it.
    B: I have done it in past games.

    Why does it not work!?!?!?!?!??!???!?!!!!

  10. #25
    Me pwn you.
    Join Date
    Feb 2006
    Location
    At my computer or in my bed.
    Posts
    46
    Hmmmmm....
    I have narrowed it down to the ITEM class, which is a tree of item types.
    For some reason I can't get the items inside the class to work.



    here it is:


    Code:
    class ITEM {
    public:
    
    int TYPE; //the type of item
    
    string NAME; //the item's name
    
    ACC    AC; //where the actual item is stored
    WEAPON WE;
    BOOK    B;
    ARMOR   A;
    
    void ShowItem(void) {//a member function for displaying items
    
    //clear screen and show item name.
    system("cls");
    cout 
    << NAME
    << "\n";
    
    //show item for correct type:
    if      (TYPE == BOOK)   {B.ShowBook();}
    else if (TYPE == AX)     {AC.ShowAcc();}
    else if (TYPE == ARMOR)  {A.ShowArmor();}
    else if (TYPE == WEAPON) {WE.ShowWeapon();}
    else {
    cout 
    << "Corrupt item: \""
    << NAME
    << "\"\n";}} //end of member function
    };//end of class

    When I try to compile it gives me all kinds of errors. Such as
    Soandso is used as a type but not defined as a type. However
    BOOK, ACC, WEAPON, and ARMOR are all classes and all
    spelled correctly and so forth. If I lose the ITEM class, it compiles perfectly. Frustration has set in and I would like a bit more help. I thank everyone who has replied for their help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. member functions can't see private data members
    By ichijoji in forum C++ Programming
    Replies: 2
    Last Post: 11-22-2006, 02:36 PM
  2. issue with member functions
    By Chaplin27 in forum C++ Programming
    Replies: 4
    Last Post: 09-27-2006, 09:18 PM
  3. Classes and member functions
    By uraliss in forum C++ Programming
    Replies: 2
    Last Post: 04-13-2006, 07:38 AM
  4. Class member variables only readable by member functions?
    By _Elixia_ in forum C++ Programming
    Replies: 4
    Last Post: 10-10-2003, 03:52 PM
  5. trouble defining member functions
    By dP munky in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2003, 08:52 PM