Thread: urgent help needed, calling function

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    Exclamation urgent help needed, calling function

    i am trying to call a function into a main program file, please can somesone help me.

    'game.h' file -
    // game.h: interface for the game class.
    //
    //////////////////////////////////////////////////////////////////////

    #if !defined(AFX_GAME_H__5304BDEF_6A7E_4CA9_AE3A_0B70F 82C6829__INCLUDED_)
    #define AFX_GAME_H__5304BDEF_6A7E_4CA9_AE3A_0B70F82C6829__ INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000

    class game
    {
    public:
    game();
    virtual ~game();
    play();


    };

    #endif // !defined(AFX_GAME_H__5304BDEF_6A7E_4CA9_AE3A_0B70F 82C6829__INCLUDED_)

    'game.cpp' file -
    // game.cpp: implementation of the game class.
    //
    //////////////////////////////////////////////////////////////////////

    #include "game.h"
    #include <iostream>

    using namespace std;

    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    game::game()
    {

    }

    game::~game()
    {

    }

    game::play() - Note thats PLAY function, with a p where the smiley is
    {
    cout<<"Welcome to the Vegas Fruit Mahcine"<<endl;
    return 0;
    }

    'main.cpp' file -
    #include <iostream>
    #include "game.h"

    using namespace std;

    int main()
    {
    play();

    return 0;
    }

    please can someone show me or tell me how to call the play function to the mian.cpp file. i know i have to put '-----.play()', but i don't know what or how to replace the ---- bit with.

    Disable Smilies in This Post ticked by Salem

  2. #2
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    798
    You need to create an instance of your 'game'.

    Code:
    int main()
    {
    
    game MyGame;
    MyGame.play();
    
    return 0;
    }

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    84
    thanks for the quick reply.

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    When you are posting, there is a check box to turn the smilies off if you like!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Function calling woes
    By RedZippo in forum C Programming
    Replies: 6
    Last Post: 01-09-2004, 12:39 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM