热门标签 | 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;

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


推荐阅读
  • CMake跨平台开发实践
    本文介绍如何使用CMake支持不同平台的代码编译。通过一个简单的示例,我们将展示如何编写CMakeLists.txt以适应Linux和Windows平台,并实现跨平台的函数调用。 ... [详细]
  • 使用C#开发SQL Server存储过程的指南
    本文介绍如何利用C#在SQL Server中创建存储过程,涵盖背景、步骤和应用场景,旨在帮助开发者更好地理解和应用这一技术。 ... [详细]
  • 本文详细介绍了macOS系统的核心组件,包括如何管理其安全特性——系统完整性保护(SIP),并探讨了不同版本的更新亮点。对于使用macOS系统的用户来说,了解这些信息有助于更好地管理和优化系统性能。 ... [详细]
  • 从 .NET 转 Java 的自学之路:IO 流基础篇
    本文详细介绍了 Java 中的 IO 流,包括字节流和字符流的基本概念及其操作方式。探讨了如何处理不同类型的文件数据,并结合编码机制确保字符数据的正确读写。同时,文中还涵盖了装饰设计模式的应用,以及多种常见的 IO 操作实例。 ... [详细]
  • Google最新推出的嵌入AI技术的便携式相机Clips现已上架,旨在通过人工智能技术自动捕捉用户生活中值得纪念的时刻,帮助人们减少照片数量过多的问题。 ... [详细]
  • 本文探讨了 C++ 中普通数组和标准库类型 vector 的初始化方法。普通数组具有固定长度,而 vector 是一种可扩展的容器,允许动态调整大小。文章详细介绍了不同初始化方式及其应用场景,并提供了代码示例以加深理解。 ... [详细]
  • 解决微信电脑版无法刷朋友圈问题:使用安卓远程投屏方案
    在工作期间想要浏览微信和朋友圈却不太方便?虽然微信电脑版目前不支持直接刷朋友圈,但通过远程投屏技术,可以轻松实现在电脑上操作安卓设备的功能。 ... [详细]
  • 本文深入探讨了 Java 编程语言的基础,特别是其跨平台特性和 JVM 的工作原理。通过介绍 Java 的发展历史和生态系统,帮助初学者理解如何编写并运行第一个 Java 程序。 ... [详细]
  • C++构造函数与初始化列表详解
    本文深入探讨了C++中构造函数的初始化列表,包括赋值与初始化的区别、初始化列表的使用规则、静态成员初始化等内容。通过实例和调试证明,详细解释了初始化列表在对象创建时的重要性。 ... [详细]
  • PHP 5.5.0rc1 发布:深入解析 Zend OPcache
    2013年5月9日,PHP官方发布了PHP 5.5.0rc1和PHP 5.4.15正式版,这两个版本均支持64位环境。本文将详细介绍Zend OPcache的功能及其在Windows环境下的配置与测试。 ... [详细]
  • 深入理解Java泛型:JDK 5的新特性
    本文详细介绍了Java泛型的概念及其在JDK 5中的应用,通过具体代码示例解释了泛型的引入、作用和优势。同时,探讨了泛型类、泛型方法和泛型接口的实现,并深入讲解了通配符的使用。 ... [详细]
  • libsodium 1.0.15 发布:引入重大不兼容更新
    最新发布的 libsodium 1.0.15 版本带来了若干不兼容的变更,其中包括默认密码散列算法的更改和其他重要调整。 ... [详细]
  • 本文介绍如何在Java项目中使用Log4j库进行日志记录。我们将详细说明Log4j库的引入、配置及简单应用,帮助开发者快速上手。 ... [详细]
  • 本文详细记录了在银河麒麟操作系统和龙芯架构上使用 Qt 5.15.2 进行项目打包时遇到的问题及解决方案,特别关注于 linuxdeployqt 工具的应用。 ... [详细]
  • 当在 Android 应用中使用 NDK 时,可能会遇到 java.lang.UnsatisfiedLinkError: Native method not found 的错误。本文将详细探讨该错误的原因及解决方案。 ... [详细]
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社区 版权所有