Like Tree1Likes
  • 1 Post By Elkvis

trying to pass an array of object

This is a discussion on trying to pass an array of object within the C++ Programming forums, part of the General Programming Boards category; im trying to pass an array of objects however i m finding some problems. any help is much appriciated thanks ...

  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,438
    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
    ZuK
    ZuK is offline
    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
    ZuK
    ZuK is offline
    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
    2,501
    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.
    Code:
    namespace life
    {
        const bool change = true;
    }

  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
    ZuK
    ZuK is offline
    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
    2,501
    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?
    stahta01 likes this.
    Code:
    namespace life
    {
        const bool change = true;
    }

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, 08: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, 12:27 PM
  5. Replies: 3
    Last Post: 04-02-2002, 12:39 PM

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