Class not seeing its avaliable attributes

This is a discussion on Class not seeing its avaliable attributes within the C++ Programming forums, part of the General Programming Boards category; Hi again one of my classes operations keeps throwing up errors saying it can't find data it should be able ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    27

    Class not seeing its avaliable attributes

    Hi again

    one of my classes operations keeps throwing up errors saying it can't find data it should be able too.

    the operation is AISnake::check_collision( ); and it is a friend of the food class

    prepare for masses of code

    AI Class
    Code:
    // Class: AISnake Implementation
    
    
            AISnake::AISnake(int x = 0, int y = 0)
            {
                //Image main_image(20, 20);
                ImageFile("../Assets/node2.tga").load(nodeimage2);
    
                AIsegments.push_front(Position(20,40));
                AIsegments.push_front(Position(40,40));
                AIsegments.push_front(Position(60,40));
                direction_ = 'n';
            }
    
            void AISnake::AIupdate()
            {
    
                AIsegments.pop_back();
                Position AI_p = AIsegments.front();
    
    
    
                // depends upon direction_
                switch(direction_)
                {
                    case 'w':
                        AI_p.x_ -= 20;
                    break;
    
                    case 's':
                        AI_p.y_ -= 20;
                    break;
    
                    case 'e':
                        AI_p.x_ += 20;
                    break;
    
                    case 'n':
                        AI_p.y_ += 20;
                    break;
                }
    
            AIsegments.push_front(AI_p);
    
            if (AI_p.x_ <= 0 || AI_p.x_ >= 800)
                {
                    aFont.print((Image.background, 400, 300, Colour(0, 0, 0)), "You WIN!");
                }
            else if (AI_p.y_ <= 0 || AI_p.y_ >= 600)
                {
                    aFont.print((Image.background, 400, 300, Colour(0, 0, 0)), "You WIN!");
                }
            }
    
    
             void AISnake::AIcheck_collision(int foodx, int foody, int snakex, int snakey)
            {
    
                int index = 0;
    
                    while (index <= 6)
    
                        {
                            int foodx = foodpositions_[index].x_;
                            int foody = foodpositions_[index].y_;
    
                            int snakex = AI_p.x_;
                            int snakey = AI_p.y_;
    
                            if(snakex == foodx)
                                {
                                    if(snakey == foody)
                                        {
                                            AIsegments.push_front((AI_p.x_ );
    
                                            for(int i= 0; i< 5 ; i++)
                                                {
                                                    foodpositions_[index] = foodpositions_[index+1];
                                                }
                                        }
                                }
                        }
    
           }
    food class attribuites
    Code:
    class food {
    
        //Attributes
    
        protected:
    
        int type_;
        Image foodImage_;
        int foodcount_;
        Position foodpositions_[5];
        friend void Snake::check_collision();
        friend void AISnake::AIcheck_collision();
      //  int foodpossiblepos[39];
    the complier says that foodpositions_ is not declared in scope and niether is AI_p.x_ and AI_p.y_

    why can't it find these?

    thanks

    ES
    Last edited by elsparko; 05-18-2010 at 04:30 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You have to have a food object in mind if you intend to get values of variables. Each and every different food object has its own foodpositions_ array, so you have to know which of those multitude of objects is the one you care about.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. MURK - a small preview
    By Mario F. in forum Game Programming
    Replies: 27
    Last Post: 12-18-2006, 08:22 AM
  4. Need help to build network class
    By weeb0 in forum C++ Programming
    Replies: 0
    Last Post: 02-01-2006, 11:33 AM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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