Thread: trying to pass an array of object

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    39

    trying to pass an array of object

    im trying to pass an array of objects however i m finding some problems. any help is much appriciated thanks
    pieces.h
    Code:
    class Cpiece{
    public:
    	
    	Cpiece* board[8][8];// array of objects
    	virtual char getcolor() =0;
    	virtual char setcolor(char colour)=0;
    	virtual char getpiece()=0;
    	char colour;
    	//char getcolour();
    	int iskill(int newcolum,int newrow);
    	void getvalue(int oldrow, int oldcolumn, int newrow, int newcolumn);
    	virtual int validate(int oldr,int oldc,int newr,int newc, int kill)=0;
    	void setvalue(int oldrow,int oldcolumn,int newrow,int newcolumn);
    	int isvalid(int oldrow, int oldcolumn, int newrow, int newcolumn);
    protected:
    	int oldr,oldc,newr,newc,kill;
    	
    
    
    };
    piece.cpp
    Code:
    nt Cpiece::isvalid(int oldrow, int oldcolumn, int newrow, int newcolumn){	int check=0;
    	char chars;
    	if(board [oldcolumn][oldrow] != NULL){
    	switch (board[oldcolumn][oldrow]->getpiece())
    	{
    	case 'p' :
    		kill = iskill(newcolumn,newrow);
    		chars = board[oldcolumn][oldrow]->getcolor();
    	   check=(*piece).validate(oldrow,oldcolumn,newrow,newcolumn,kill);// i need to pass the board over here
    
    
    	   break;
    	}
    	}
    	if(check ==1){
    		getvalue(oldrow,oldcolumn,newrow,newcolumn);
    
    
    	}
    
    
    	return check;
    
    
    }
    cpiece.cpp
    Code:
     int Cponn::validate(int oldr,int oldc,int newr,int newc,int kill)// where the board must be recieved{	 int check=0;
    	 char col;
    	 
    	 if(((oldc+1) == newc) && oldr==newr&& kill ==0){
    		 check =1;
    
    
    	 }
    	 if(((oldc+1) ==newc) && ((oldr+1) == newr) && (kill ==1)){
    		 check =1;
    	 }
    	 
    	 
    		if(((oldc-1) == newc) && oldr==newr&& kill ==0){
    		 check =1;
    
    
    	 }
    	 if(((oldc-1) ==newc) && ((oldr-1) == newr) && (kill ==1)){
    		 check =1;
    	 }
    
    
    
    
    	 
    	 return check;
     }

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    you have 32 posts, been a member for 12 months - you can form a better question than that?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    39
    i need to pass board to function validate what i need to do

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Why would you want to pass it to validate ?
    board is a public member of Cpiece, it is accessibe anyway.
    Kurt

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    39
    i need to pass it as a pointer

  6. #6
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by kdun View Post
    i need to pass it as a pointer
    Why ?
    Kurt

  7. #7
    Registered User
    Join Date
    Apr 2012
    Posts
    39
    i need to pass it so that i could read the info of the board if i dont pass it it is all null

  8. #8
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Cponn is derived from Cpiece, so it has access to everything Cpiece declares publicly. you don't need to pass it. you can say this->board, or this->Cpiece::board or even just board. you don't need to pass it as a parameter.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  9. #9
    Registered User
    Join Date
    Apr 2012
    Posts
    39
    im trying to make this but its not working

    Code:
    col= board[1][1]->getcolor;
    Code:
    char Cponn::getcolor(){	 return col;
     }

  10. #10
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    try
    Code:
    col= board[1][1]->getcolor();
    kurt

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by kdun View Post
    but its not working
    this is literally the most useless thing you can say.

    how is it not working?

    what errors does it produce, if any?

    what have you tried to resolve it?
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need to pass an object as a pointer in function
    By kdun in forum C++ Programming
    Replies: 7
    Last Post: 04-12-2013, 03:20 PM
  2. Pass object to function
    By swgh in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2008, 07:57 AM
  3. how to pass an ifstream object to a function
    By chintugavali in forum C++ Programming
    Replies: 14
    Last Post: 12-18-2007, 09:58 PM
  4. pass all the array as blob object in one field
    By Leite33 in forum Windows Programming
    Replies: 0
    Last Post: 11-12-2006, 01:27 PM
  5. Replies: 3
    Last Post: 04-02-2002, 01:39 PM