Click here to Skip to main content
15,885,074 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
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[^]

C++
#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
Comments
The_Inventor 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 18-May-13 7:12am    
right. where should i put them then?
Richard MacCutchan 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.

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:
Objective-C
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:
Objective-C
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:
C#
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:

C#
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...
 
Share this answer
 
v3
Comments
Mohammad Moqadam 21-May-13 4:21am    
thank u... really..
the name of the compiler is turbo c++. how it's not c++?
The_Inventor 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.
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.
 
Share this answer
 
Comments
Mohammad Moqadam 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900