   calling a class through a function
  Hi.I''m a beginner in c++. I want to create an object with a class and then draw it in opengl.however i''m struggling to call the class outside of my main function. the code looks like the followingclass ship{protected:// init variables here including public:ship(){}float shipstart ( float x, float y, float z){ shipworldx = x; shipworldy = y; shipworldz = z;shipspeed = 0;shipheading = 0;shipcolor [0] = 0.5; //set color to somethingshipcolor [1] = 0.5;shipcolor [2] = 0.5;}// some other misc declarations}// i then setup opengl and glut and my function defenitions. this works.// now in main i call and setup the shipsship blueship[3]; // create 3 objects called ships   blueship[0].shipstart (0,0,0); // x,y,z coords blueship[1].shipstart (0,5,0);    blueship[2].shipstart (2,4,2);// now i have just opengl calls as usualglutInit(&argc,argv);glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_ACCUM | GLUT_DEPTH);glutInitWindowSize (1024,768);glutInitWindowPosition (200,100);glutCreateWindow (argv[0]);init();glutDisplayFunc(display);glutReshapeFunc(reshape);glutKeyboardFunc(keyboard);glutIdleFunc(idle);   glutMainLoop();return 0;}// now this is where the problem comes.// i have a function called by my ''display'' function that''s called  drawship which draws a ship// or it should. but i always get a error// it seems the function can''t see the class i made earliervoid drawships(void) {int i;for (i=0; i.draw_ship();} } so my question is this - how can i get the function to see my class. I have google searched and searched here on devnet. i found lots of interetsting info but none that helped my specific question.cheersPS - forgive the ugly code and layout. i am a rank beginner. but am reading ''interactive c++'' book by Robert Lafore which is great. now all i need is a great brain 
  You can simply declare your blueship classes outside main (make it global) so it'll be visible to your other function. Or a better solution  would be to pass your classes as a pointer to the function   [edited by - PatrickD on February 4, 2004 7:47:04 AM];  i 2nd that answer....do we have a 3rd ? "A soldier is a part of the 1% of the population that keeps the other 99% free"  - Lt. Colonel Todd, 1/38th Infantry, Ft. Benning, GA ;  Yup. third. Your biggest problem here is structure. But as you progress with c++ you will learn all sorts of things that are wrong woth this code. But thats what learning is about.. enjoy. ;  I''m a bit sleepy, but I think I''m awake enough to see that this is wrong... void drawships(void){int i;for (i=0; i {blueship.draw_ship();}}Shouldn''t it be more like this? void drawships(void){ int i; for(i=0; i<3; i++)  blueship[i].draw_ship();};void drawships(void) {int i;for (i=0; i<NUMships; i++){   blueship[i].draw_ship();} }l3mon, I think the forum ate his < and .   ;  thanks for your replies.this question has had stumped me for 3 days.such a wonderfully simple solution.now i''ll call the classes before main(). but the pointer thing sounds interesting, i''ll have to read up on that. and yes the forum somehow ate the end of my for-loop. greedy bugger - you think with all the posts the firum gets it would be satisfied, but noooo actually the cut off text is my fault cause i don''t know how to put the neat white box around my code in a post. But i''ll learn that to in time.;  Take a look in the FAQ