C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28630
Number of posts: 94612

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
why won't this work? Posted by Ghoti_01 on 17 Nov 2006 at 7:58 AM
the numbers the user enters in the main don't transfer into the implementation file.




//Header File

public:
//constructor
Matrix();
Matrix(int&, int&);

private:
int* column;
int* row;
int board[3][3];

//Implementation File


Matrix::Matrix(int& r, int& c)
{
row = &r;
column = &c;

for(int i =0; i < 3;i++)
{
for(int j = 0; j < 3; j++)
board[i][j] = 0;
}
}

//Main File

int r;
int c;

Matrix board(r, c);

cout << "Player 1 move: ";
cin >> r >> c;
board.playerOneMoves();
board.displayBoard();

cout << "Player 2 move: ";
cin >> r >> c;
board.playerTwoMoves();
board.displayBoard();
Report
Re: why won't this work? Posted by Donotalo on 17 Nov 2006 at 8:42 AM
: the numbers the user enters in the main don't transfer into the implementation file.
:
:
:
:
: //Header File
: 
:    public:
:              //constructor
:              Matrix();
:              Matrix(int&, int&);
: 
:         private:
:               int* column;
:               int* row;
:               int  board[3][3];
: 
: //Implementation File
: 
: 
: Matrix::Matrix(int& r, int& c)
: {
:     row = &r;
:     column = &c; 
: 
:     for(int i =0; i < 3;i++)
:     {
:       for(int j = 0; j < 3; j++)
:       board[i][j] = 0;
:     } 
: }
: 
: //Main File
: 
:        int r;
:        int c;       
: 
:        Matrix board(r, c);       //r, c are not initialized
:  
:        cout << "Player 1 move: ";
:        cin >> r >> c;   //r, c are initialized here
:        board.playerOneMoves();     
:        board.displayBoard();
:      
:        cout << "Player 2 move: ";
:        cin >> r >> c;  
:        board.playerTwoMoves();
:        board.displayBoard();
: 

u r sending the numbers before they are initialized by the user.


~Donotalo()




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.