Why wont this work??

This is a discussion on Why wont this work?? within the C++ Programming forums, part of the General Programming Boards category; Help Please. There are 3 seperate files. Ive narrowed down the error. Code: #ifndef GUARD_Character_Info #define GUARD_Character_Info #include <iostream> #include ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    230

    Why wont this work??

    Help Please. There are 3 seperate files. Ive narrowed down the error.

    Code:
    #ifndef GUARD_Character_Info
    #define GUARD_Character_Info
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    
    class Character_Info
    {   
        private:
        char player_name[50];  //players name
        
        public:
        void name() //get players name
        {    
            cout <<"Enter your players name."<<endl;
            cin >>player_name;
            cout<<"You have entered"<<endl<<player_name<<endl;
        }
        void infOut(int pn) // !!!!!!!!part of the error
        {
            ofstream charout;
                
            charout.open("CHARACFILE.DAT", ios::app | ios::binary);
            charout.write( (char*)this, sizeof(*this));
        }
    };
    
    
            
    #endif
    Code:
    #include <iostream>
    #include <conio.h>
    #include "Intro.h"
    #include "Character_Info.h"
    using namespace std;
    
    int main()
    {
        Intro I1;
        I1.Display_Intro();
        getch();
        return 0;
    }
    Code:
    #ifndef GUARD_Intro
    #define GUARD_Intro
    #include <iostream>
    #include "Character_Info.h"
    
    using namespace std;
    
    class Intro: public Character_Info
    {   
        private:
        int ch; //users choice on switch
        public:
        void Display_Intro() // display and get name
        {
            cout <<" You have just entered the world of Lost Dungeons"<<endl;
            cout <<" You will be taken on a long journey of trouble and danger."<<endl;
            cout <<" If you are up to the task then select your choice (1 or 2):"<<endl;
            
            cin >> ch;
            
            switch (ch)
            {
                    case 1:
                    Character_Info::name();
                    Character_Info::infOut(); //!!!!!other part of error
                    break;
                    case 2:
                    cout <<"Quitting program";
                    break;
                    default:
                    cout <<"ERROR";
                    
            }
        }
    here are my compiler errors
    ------------------------------------------------------------------------------------
    3 C:\Dev-Cpp\Main.cpp
    In file included from Main.cpp
    C:\Dev-Cpp\Intro.h
    In method `void Intro:isplay_Intro()':
    25 C:\Dev-Cpp\Intro.h
    no matching function for call to `Character_Info::infOut ()'
    21 C:\Dev-Cpp\Character_Info.h
    candidates are: void Character_Info::infOut(int)
    C:\Dev-Cpp\Makefile.win
    [Build Error] [Main.o] Error 1
    ------------------------------------------------------------------------------------



    any help will be welcome. thank you in advance. i might not respond till tomorrow so i posted so that you can answer or look into it early.Thank you
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    because you defined

    nfOut

    to take an integer as a parameter, but when you called it you didn't pass any parameters.


    Also, when calling the member function from within an object or a child object, as long as the function isn't redefined in the class or a parent, you don't have to use the classname and operator :

    You can instead call it just like if it was a regular function

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    thx but im still not getting it to work. Could you show me an example of how to do it.


    NOTE GOING TO BED NOW
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    just change the member definition to

    Code:
        void infOut()
        {
            ofstream charout;
                
            charout.open("CHARACFILE.DAT", ios::app | ios::binary);
            charout.write( (char*)this, sizeof(*this));
        }
    The other thing you can change is

    Code:
    name();
    infOut();
    When they are called in display info

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 08:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 05:36 PM

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