Can you please help me

Hi

I am trying to pass a object by reference with pointer into a function
and using a method in that object. By seem to me it doesn't work.

The object i want to pass is Game and in Game have a function vector
<char> getPuzzle ();

I pass game into the function

bool guess (Game* game){
//do something here

vector <char> p = game->getPuzzle();
//do something here too
}

it will compile but when i run it it come back with the error message

This application has requested the Runtime to terminate it in an
unusual way.
Please contact the application's support team for more information.

Can you please tell me is that the correct way of using it What
should i do to avoid this kind of error
I am quite new to C++ so please forgive me if the question is not
appropriate.
Thanks a lot


Answer this question

Can you please help me

  • dustinto

    Hi,
    it's hard to tell what's wrong with your code since it appears correct and maybe it's not this sample that's causing the problem. Did you use the debugger to check where the error is
    Are you passing a valid object to this function guess

    It could be a lot of things, you better post your complete code (or reduce the sample to a simple case if your code is to big to post) somewhere so we can help you better.


  • rWarrior

    Hi guyz thanks for your help. The problem is on the previous code that i wrote. The game object that i passed in not a valid.


  • Phil Rogers

    Can't see anything wrong with your code. Maybe game is not a valid pointer to an instance of Game. Have you used a debugger to find out where the exception occurs
  • dvdribeiro

    As Ricardo (n0n4m3) indicates, it helps to create a simple sample of the problem; a small program that only has the minimum necessary to duplicate the problem. That could help you diagnose the problem and develop a solution but if you need help then it really helps others to help you if you have a complete sample that is small enough to be practical to look at.

  • bw12117

    Ha Duo wrote:
    Hi

    This application has requested the Runtime to terminate it in an
    unusual way.
    Please contact the application's support team for more information.

    That probably means that the Game pointer you are passing isn't initialized properly.

    Make sure your application resembles:

    class Game
    {
    public:
    Game()
    {
    // Fill puzzle with something meaningful
    }

    vector<char> getPuzzle()
    {
    return puzzle;
    }

    private:
    vector<char> puzzle;
    };

    bool guess(Game* g)
    {
    vector <char> p = game->getPuzzle();
    ...
    }

    void myFunction()
    {
    Game g;
    guess(&g);
    }



  • Can you please help me