热门标签 | HotTags
当前位置:  开发笔记 > 程序员 > 正文

VS2013编译不通过,errorC2143:语法错误:缺少“;”(在“<”的前面)

这是AStar.h头文件

这是AStar.h头文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include

#include//双端队列

#include





#define STEP 10//单位长度

#define STEP_DIAGONAL 14//单位对角线长度



class Node{

private:

    int x;

    int y;

    int g;//沿着生成的路径,从开始节点到指定区域的移动消耗(可以沿对角线走)

    int h;//估算从指定区域格子到目的地格子的移动消耗(只准横着走,竖着走)

    int f;//F=G+H

    Node *father;

public:

    static deque open, closed;

    Node();

    Node(int x, int y);

    void setX(int x);

    void setY(int y);

    void setG(int g);

    void setH(Node &goal);

    void setF();

    void setFather(int x, int y);

    void setFather(Node &father);

    void setFather(Node *father);

    int getX();

    int getY();

    int getG();

    int getH();

    int getF();

    Node* getFather();

    static void addBarrier(int x, int y);

    static void addBarrier(Node barrier);

    Node operator=(const Node&);

    bool operator==(const Node&);

    Node createSunNode(int direction, Node goal);

    static void addToOpen(Node node);

    static void addToOpenWithOpenNotHave(Node node);//已经确认不在open表中

    static void addToClosed(Node node);

    static bool isInOpen(Node node);

    static bool isInClosed(Node node);

    void printNode();

};


这是AStar.cpp文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include

#include

#include

#include

#include

#include"AStar.h"



const int LEFT = 0;

const int LEFT_UP = 1;

const int UP = 2;

const int UP_RIGHT = 3;

const int RIGHT = 4;

const int RIGHT_DOWN = 5;

const int DOWN = 6;

const int LEFT_DOWN = 7;



using namespace std;



Node::Node() :x(0), y(0), g(0), h(0), f(0)

{

}



Node::Node(int x, int y) : x(x), y(y), g(0), h(0), f(0)

{

}



void Node::setX(int x)

{

    this->x = x;

}



void Node::setY(int y)

{

    this->y = y;

}



void Node::setG(int g)

{

    this->g = g;

}

void Node::setH(Node &goal)

{

    this->h = abs(goal.x - this->x) + abs(goal.y-this->y);//横坐标差的绝对值+纵坐标差的绝对值

}



void Node::setF()

{

    this->f = this->g + this->h;

}



void Node::setFather(int x, int y)

{

    this->father->x = x;

    this->father->y = y;

}



void Node::setFather(Node &father)

{

    this->father->x = father.x;

    this->father->y = father.y;

    this->father->g = father.g;

    this->father->h = father.h;

    this->father->f = father.f;

}



void Node::setFather(Node *father)

{

    this->father->x = father->x;

    this->father->y = father->y;

    this->father->g = father->g;

    this->father->h = father->h;

    this->father->f = father->f;

}



int Node::getX()

{

    return x;

}



int Node::getY()

{

    return y;

}



int Node::getG()

{

    return g;

}



int Node::getH()

{

    return h;

}

int Node::getF()

{

    return f;

}

Node* Node::getFather()

{

    return father;

}



void Node::addBarrier(int x, int y)

{

    Node node(x,y);

    closed.push_back(node);

}



void Node::addBarrier(Node barrier)

{

    closed.push_back(barrier);

}



Node Node::operator=(const Node& nodeOrigin)

{

    this->x = nodeOrigin.x;

    this->y = nodeOrigin.y;

    this->g = nodeOrigin.g;

    this->h = nodeOrigin.h;

    this->f = nodeOrigin.f;

   

    this->setFather(nodeOrigin.father);



    return *this;

}



bool Node::operator==(const Node& node)

{

    return this->x==node.x&&this->y==node.y;

}



Node Node::createSunNode(int direction, Node goal)

{

    Node sun = *this;//C++在this对象指针前面加*表示对象。

    //

    switch (direction)

    {

    case LEFT:

        sun.setX(sun.getX() - 1);

        break;

    case LEFT_UP:

        sun.setX(sun.getX() - 1);

        sun.setY(sun.getY() - 1);

        break;

    case UP:

        sun.setY(sun.getY() - 1);

        sun.setG(sun.getG()+STEP);

        break;

    case UP_RIGHT:

        sun.setX(sun.getX() + 1);

        sun.setY(sun.getY() - 1);

        break;

    case RIGHT:

        sun.setX(sun.getX() + 1);

        break;

    case RIGHT_DOWN:

        sun.setX(sun.getX() + 1);

        sun.setY(sun.getY() + 1);

        break;

    case DOWN:

        sun.setY(sun.getY() + 1);

        break;

    case LEFT_DOWN:

        sun.setX(sun.getX() - 1);

        sun.setY(sun.getY() + 1);

        break;

    default:

        break;

    }



    if (direction%2==0)

    {

        //上下左右直走,STEP

        sun.setG(sun.getG()+STEP);

    }

    else

    {

        //对角线,STEP_DIAGONAL

        sun.setG(sun.getG()+STEP_DIAGONAL);

    }

    sun.setH(goal);

    sun.setF();

    //



    return sun;

}



void Node::addToOpen(Node node)

{

    if (isInClosed(node))

    {

        return;

    }

    //检查是否在open

    bool isInOpen = false;

    deque::iterator iter;//iter是Node*类型

    for (iter = open.begin(); iter != open.end();iter++)

    {

        if (*iter==node)

        {

            isInOpen = true;

            break;

        }

    }

   

    if (isInOpen)

    {

        //是否G成本更低

        if (node.getG()<(iter->getG()))

        {

            //是,改变在open表中的这个node节点的父节点

            iter->setFather(node.getFather());

            //重新根据F值排序

            Node temp = *iter;

            open.erase(iter);

            //iter不能再用了,因为删除操作使iter失效了

            addToOpenWithOpenNotHave(temp);

        }

        else

        {

            //否,do nothing

        }

    }

    else

    {

        addToOpenWithOpenNotHave(node);

    }

}



//已经确认要添加的node不在open表中

void Node::addToOpenWithOpenNotHave(Node node)

{

    //不在open表中,加入open(open表按F值从大到小排列)

    if (open.size()>0)

    {

        for (int i = open.size() - 1; i >= 0; i--)

        {

            if (open[i].getF() >= node.getF())

            {

                //这里可能有问题

                open.insert(open.begin() + i, node);

                break;

            }

            else

            {

                if (i == 0)

                {

                    open.push_front(node);

                }

            }

        }

    }

    else

    {

        open.push_back(node);

    }

}



void Node::addToClosed(Node node)

{

    closed.push_back(node);

}



bool Node::isInOpen(Node node)

{

    bool isInOpen = false;

    deque::iterator iter;//iter是Node*类型

    for (iter = open.begin(); iter != open.end(); iter++)

    {

        if (*iter == node)

        {

            isInOpen = true;

            break;

        }

    }

    return isInOpen;

}



bool Node::isInClosed(Node node)

{

    bool result = false;

    for (int i = 0; i
    {

        if (closed[i] == node)

        {

            return true;

        }

    }

    return result;

}



void Node::printNode()

{

    cout <<"x = "<x<
        <<"y ="<y<
        <<"g = "<g<
        <<"h = "<h<
        <<"f = "<f<
}


test.cpp文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include"AStar.h"

#include



using namespace std;



int main()

{

    Node original(1,2);

    Node goal(5,2);

    Node::addToClosed(goal);

    Node::addToOpenWithOpenNotHave(original);

    Node::addBarrier(3,1);

    Node::addBarrier(3,2);

    Node::addBarrier(3,3);



    Node lastOne= Node::open.back();

    if (lastOne==goal)

    {

        cout <<"success" <
        lastOne.printNode();

    }

    Node::closed.push_back(lastOne);

    Node::open.pop_back();



    //生成并添加子节点

    for (int i = 0; i <8;i++)

    {

        Node sun = lastOne.createSunNode(i, goal);

        Node::addToOpen(sun);

    }



    return 0;



}

其中在AStar.h头文件的

1
static deque open, closed;

这一行,编译报错
报错详情


推荐阅读
author-avatar
蟹子萝卜控
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有