Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
i asked question here:undefined symbol c++ problem[^]
i took the advice and i changed the code. but there is still errors: http://upcity.ir/images2/65645793150446125725.jpg[^]
 
#include<graphics.h>
#include<dos.h>
#include<conio.h>
class car{
int spX[20]={0};
int spY[20]={0};
void Drawcar(){
setcolor(15);
line(spX[1],spY[1],spX[2],spY[2]);
line(spX[2],spY[2],spX[3],spY[3]);
line(spX[3],spY[3],spX[4],spY[4]);
line(spX[4],spY[4],spX[4],spY[4]);
line(spX[1],spY[1],spX[4],spY[4]);
pieslice(100,400,40,10,25);
arc(spX[0],spY[0]=75;,90,190,30);
circle(100,400,25);
}
 
void move_sp(int a){
for(int i=0;i<=20;i++){
spX[i]+=a;
spY[i]+=a;
Drawcar();
}
};
 
}
int main(){
int g=DETECT,m;
initgraph(&g,&m,"c:\\turboc3\\bgi");
 

spX[0]=75;
spY[0]=375;
spX[1]=75;
spY[1]=345;
spX[2]=125;
spY[2]=300;
spX[3]=225;
spY[3]=330;
spX[4]=275;
spY[4]=345;
spX[5]=300;
spY[5]=350;
 
move_sp(1);
 

getch();
closegraph();
return 0;
}
 

 

 
Posted 18-May-13 1:44am
Comments
The_Inventor at 18-May-13 7:02am
   
In C++, you can only initialize static member In the header file (*.h) or within the class structure, of a single file containing both header info, and implementation info(*.cpp)
Mohammad Moqadam at 18-May-13 7:12am
   
right. where should i put them then?
Richard MacCutchan at 18-May-13 7:12am
   
Remove the class statement and associated braces from your code. There is nothing class related in the rest of the code.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I just looked at your original error statement. Since you are working in 'C' AND_NOT 'C++',(try and give a guy a hint, hmmph)get rid of the: 'class car{' and make a more ordered struct, including only the constants and variables, and no functions.
 
Like:
struct spCar{
              int spX;
              int spY;
            }
struct edgeLine{
              spCar strtPT1;
              spCar strtPT2;
               }
 
struct theShape{
             edgeLine line1;
             edgeLine line2;
             edgeLine line3;
             edgeLine line4;
               }
 
enum Shape{line, angle, triangle, rectangle, square, ...};
 
    edgeLine L1, L2, L3, L4, L5, L6, L7, L8;
    spCar pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8;
 

bool SetPoints(int nShape)
{
    switch(nShape)
   {
     case square:
     pt1.spX = 75;
     pt1.spY = 375;
     pt2.spX = 75;
     pt2.spY = 345;
     pt3.spX = 125;
     pt3.spY = 300;
     pt4.spX = 225; ///There is some kind of error in your///
     pt4.spY = 330; ///Original Drawcar function.///
     pt5.spX = 275;
     pt5.spY = 345;
     pt6.spX = 300;
     pt6.spY = 350;
     break;
 
    ....
   }
 
    return true;
}
 
void drawShape(int shpNum, int nColor)
{
    setcolor(nColor);
    switch(shpNum) 
   {
      case square://4 sided object
      SetPoints(4, square);
      L1={pt1,pt2}; L2={pt2,pt3}; L3={pt3,pt4}; L4={pt4,pt1}; 
        line(L1);
        line(L2);
        line(L3);
        line(L4);
      break;
      case 1:
        line();
        line();
        line();
        line();
      break;
   }
}
 
Then you could put other variables or static const type data in it as if needed.
Then next a Graphics function:
void DrawCar(spCar car, int nColor, int shpNum)
{
    setcolor(nColor);
    pieslice(100,400,40,10,25);
    arc((car.spX, car.spY = 75),90,190,30);//not sure of your arc function type//
    circle(100,400,25);
    drawShape(shpNum,nColor);
 
}

 
Rewrite your move function:
void move_sp(int a, spCar car, int shpNum)
{
    for(int i = 0; i < = 20; i++)
    {
       car.spX += a;
       car.spY +=a;
       DrawCar(car, setcolor(15), shpNum);
    }
}
 
then you can do your 'main' function:
 
int main()
{
    int g=DETECT,m; spCar Car; int Shape; int Color;  
    //to do set Color to a number that works, and decide on a shape(square for the example)//
    //and set the initial point 'Car'.     
    initgraph(&g,&m,"c:\\turboc3\\bgi");
    DrawCar(car, Color, Shape);
    move_sp(1, car, Shape);
    getch();
    closegraph();
    return 0;
}
 
Or something like that...
  Permalink  
v3
Comments
Mohammad Moqadam at 21-May-13 4:21am
   
thank u... really..
the name of the compiler is turbo c++. how it's not c++?
The_Inventor at 21-May-13 4:31am
   
When it comes to C++, it best to keep the structures in the header file, and the implementation in the .cpp file. When the file just ends in *.c it is looked at like a 'c' file.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

When I said "move the definition spX and spY outside the Main function" I didn't mean into a different function!
They need to be outside any function, so that any of them can access the same data. And variable you define within a function is local to that function only.
  Permalink  
Comments
Mohammad Moqadam at 18-May-13 7:18am
   
ty so much :*

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 /\jmot 175
4 Shweta N Mishra 161
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 22 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100