c++ - Was not declared in this scope issue -


i'm checking see , understand else's code... code worked in computer, when tried edit in mine, doesn't seem work. lib files connected thou...

#include "play.h" #include "lib110ct/lib110ct.h" #include <ctime>   int main(int argc, char** argv) { win110ct win; turtle * t = win.getturtle(); win.hideturtle(); const int numofbook = 7; player you(512,384); book b[numofbook]; int pts = 0; char in; time_t ti; while (in != 'x') {     (int = 0; i<numofbook; i++)     {         if (a[i].isreadby(you))         {             b[i].setposition(rand() % 1024 + 1,rand() % 768 + 1);             pts++;         }         b[i].move();         b[i].draw(t);     }     you.draw(t);     win << "points: " << pts << "\n";     win.render();     win.setposition(-1,-1);     in = win.getchar();     win.clearback();     win.clear();     win.setposition(0,0);     if (in == 'w')         you.moverelative(0,-50);     else if (in == 's')         you.moverelative(0,50);     else if (in == 'a')         you.moverelative(-50,0);     else if (in == 'd')         you.moverelative(50,0); } return 0; } 

however run error... "book" not declared in scope.

the header play.h file's code follows..

#include "lib110ct/lib110ct.h" #include <cstdlib>  //player class, used create controllable character. class player { protected: double xpos, ypos; public: player(){}; //constructor, user input variables stored xpos , ypos, player drawn player(double x, double y) {     xpos = x;     ypos = y; }  //draws new position of turtle void draw(turtle* t) {     t->setposition(xpos,ypos);     t->pendown();     (int = 0; < 180; i++ )     {         t->turn(2);         t->moveforward(1);     } }   double getx(){ return xpos; } //returns x position of player double gety(){ return ypos; } //returns y position of player  //moves player x increment , y increment (leave x or y 0 not move along respective axis) //relative current position void moverelative(double xadd, double yadd) {     if (xpos+xadd > 0 && xpos+xadd < 1024 && ypos+yadd > 0 && ypos+yadd < 768)     {         xpos += xadd;         ypos += yadd;     } } };  //food class. not controlled player class food { protected: double xpos, ypos, xdir, ydir; public: //constructor, random x , y co-ordinates stored xpos , ypos. food drawn in       co-ordinates //random xdir , ydir, food moves in direction food() {     xpos = rand() % 1024 + 1;     ypos = rand() % 768 + 1;     xdir = rand() % 41 - 20;     ydir = rand() % 41 - 20; } //draws food void draw(turtle* t) {     t->setposition(xpos,ypos);     t->pendown();     (int = 0; < 4; i++ )     {         t->turn(90);         t->moveforward(20);     } } double getx(){ return xpos; } //returns x position of player double gety(){ return ypos; } //returns y position of player  //moves food specific location, not relative current position void setposition(double x,double y) {     xpos = x;     ypos = y; }  //moves food in specified directions, given variables xdir , ydir void move() {     if (!(xpos+xdir>0 && xpos+xdir<1024 && ypos+ydir>0 && ypos+ydir<768))     {         xdir = -xdir;         ydir = -ydir;     }     xpos += xdir;     ypos += ydir; }  //returns true if player in close proximity food, otherwise false bool iseatenby(player play) {     double px = play.getx();     double py = play.gety();     double fx = getx();     double fy = gety();     return px+60>fx && px-20<fx & py+40>fy && py-40<fy; } }; 

you trying use array of type 'book', class intended define:

book b[numofbook]; 

however, have not defined in code posted above, or in code put in dropbox.

either add definition class book play.h, or create new header file, perhaps called book.h, definition , #include "book.h" in cpp file. book class need methods setposition, move , draw.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -