免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4227 | 回复: 11

不会写main函数,调用 [复制链接]

论坛徽章:
0
发表于 2010-03-14 20:14 |显示全部楼层
本帖最后由 presidentccj 于 2010-03-14 23:28 编辑

maze.cpp: In function `int mazepath(int (*)[10], item*, int, int)':
maze.cpp:82: error: expected primary-expression before '{' token
maze.cpp:82: error: expected `;' before '{' token
  1. #include<iostream>
  2. using namespace std;
  3. #define m 6 //迷宫的实际行
  4. #define n 8 //迷宫的实际列

  5. typedef struct
  6. {int x,y,d; //横纵坐标及方向
  7. }DataType ;

  8. class SeqStack{
  9. private:
  10. DataType *base; //栈底指针
  11. DataType *top; //栈顶指针始终指向栈顶元素的后一个位置
  12. int size; //栈的大小
  13. public:
  14. SeqStack(int stacksize=100){ base=new DataType [stacksize];
  15. top=base;
  16. size=stacksize;

  17. }; //构造了一个空栈,默认大小为100个单元
  18. ~SeqStack(){ delete[] base;
  19. }; //销毁一个已存在的栈
  20. int Empty_Stack(); //判断栈是否为空
  21. int Push_Stack(DataType e); //将元素e插入到栈顶
  22. int Pop_Stack(DataType &e); //从栈顶删除一个元素到e中返回
  23. int GetTop_Stack(DataType &e); //从栈顶取出一个元素到e中返回
  24. };

  25. int SeqStack::Empty_Stack() //判断栈是否为空
  26. {
  27. return ((top<=base));
  28. }

  29. int SeqStack::Push_Stack(DataType e) //进栈操作
  30. { if(top-base<size)
  31. { *top=e;
  32. top++;
  33. return 1;
  34. }
  35. else
  36. return 0;
  37. }

  38. int SeqStack::Pop_Stack(DataType &e) //出栈操作
  39. { if(top>base)
  40. { top--;
  41. e=*top;
  42. return 1;
  43. }
  44. else
  45. return 0;
  46. }
  47. int SeqStack::GetTop_Stack(DataType &e) //取栈顶元素操作
  48. { if(top>base)
  49. { e=*(top-1);
  50. return 1;
  51. }
  52. else
  53. return 0;
  54. }

  55. typedef struct
  56. { int x,y;
  57. } item ;
  58. item move[4];


  59. int mazepath(int maze[m+2 ][n+2 ],item *move,int x0,int y0)
  60. { //求迷宫路径,入口参数:指向迷宫数组的指针,指向移动方向的指针,
  61. //开始点(x0,y0),到达点(m,n),返回值:1表示求出路径,0表示无路径
  62. SeqStack S ;
  63. DataType temp ;
  64. int x, y, d, i, j ;
  65. temp.x=x0 ; temp.y=y0 ; temp.d=-1 ;
  66. S.Push_Stack(temp) ;
  67. while (!S.Empty_Stack() )
  68. { S.Pop_Stack(temp) ;
  69. x=temp.x ; y=temp.y ; d=temp.d+1 ; maze[x][y]=0;
  70. while (d<4)
  71. { i=x+move[d].x ; j=y+move[d].y ;
  72. if (maze[i][j]==0)
  73. {        temp={x, y, d};
  74.         S.Push_Stack(temp) ;
  75.         x=i ; y=j ; maze[x][y]= -1 ;
  76.         if (x==m&&y ==n) //迷宫有路
  77.         { while (!S.Empty_Stack() )
  78.         { S.Pop_Stack(temp);
  79.         cout<<temp.x<<temp.y ;
  80. }
  81. return 1 ;
  82. }
  83. else d=0 ;
  84. }
  85. else d++ ;
  86. } //while (d<4)
  87. } //while
  88. return 0 ;//迷宫无路
  89. }

  90. int main()
  91. {
  92.          int mazepath(int maze[m+2 ][n+2 ],item *move,int x0,int y0);
  93.         return 0;
  94. }
复制代码

论坛徽章:
0
发表于 2010-03-14 20:59 |显示全部楼层
回复 1# presidentccj


            {        //temp={x, y, d};
                        temp.x = x;
                        temp.y = y;
                        temp.d = d;

论坛徽章:
0
发表于 2010-03-14 21:05 |显示全部楼层
加上参数-std=c++0x试试。

论坛徽章:
0
发表于 2010-03-14 21:05 |显示全部楼层
g++ maze.cpp -std=c++0x

论坛徽章:
0
发表于 2010-03-14 21:11 |显示全部楼层
这样的扩展赋值在ISO中不允许。加上-std=c++0x使用一些实验功能。

论坛徽章:
0
发表于 2010-03-14 21:48 |显示全部楼层
本来就加了的;还有main函数不会写{:3_182:}

[root@ccj point]# gcc  -o maze maze2.cpp  -lstdc++
maze2.cpp: In function `int main()':
maze2.cpp:84: error: expected primary-expression before '{' token
maze2.cpp:84: error: expected `;' before '{' token

论坛徽章:
0
发表于 2010-03-14 21:50 |显示全部楼层
g++ maze.cpp -std=c++0x
lengyuex 发表于 2010-03-14 21:05



     g++ maze.cpp -std=c++0x
cc1plus: error: unrecognized command line option "-std=c++0x"

论坛徽章:
0
发表于 2010-03-14 21:55 |显示全部楼层
回复  presidentccj


            {        //temp={x, y, d};
                        temp.x = x;
                        temp.y = y;
                        temp.d  ...
rain_fish 发表于 2010-03-14 20:59



    这样不错了,呵呵,main函数我不会写

论坛徽章:
0
发表于 2010-03-14 21:58 |显示全部楼层
g++ maze.cpp -std=c++0x
cc1plus: error: unrecognized command line option "-std=c++0x"
presidentccj 发表于 2010-03-14 21:50



    没有这个选项?g++版本太旧了吧。

论坛徽章:
0
发表于 2010-03-14 22:01 |显示全部楼层
回复 9# lengyuex


    是的gcc version 3.4.6
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP