urgent help needed, calling function

This is a discussion on urgent help needed, calling function within the C++ Programming forums, part of the General Programming Boards category; i am trying to call a function into a main program file, please can somesone help me. 'game.h' file - ...

  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
    801
    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,831
    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, 12:45 PM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  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, 02:27 PM

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