gpt4 book ai didi

c++ - 尝试在 C++ 中使用列表时编译错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:36:09 25 4
gpt4 key购买 nike

我试图在 C++ 中使用列表,但出现以下错误:

1>error C2143: syntax error : missing ';' before '<'

1>error C4430: missing type specifier int assumed. Note: C++ does not support default-int

1>error C2238: unexpected token(s) preceding ';'

使用以下代码:

#pragma once

#include "Includes.h"

class Polygon
{
public:
Polygon(void);
~Polygon(void);

void addVertice(hgeVector v);
void renderPolygon();
list<hgeVector> vertices;
};

包括.h:

#ifndef INCLUDES
#define INCLUDES

#define safe_delete(d) if(d) { delete d; d=0; }
#define PI 3.14159
#include <stdio.h>
#include <list>
#include "\include\hge.h"
#include "\include\hgesprite.h"
#include "\include\hgefont.h"
#include "\include\hgeparticle.h"
#include "\include\hgerect.h"
#include "Car.h"
#include "HelperFunctions.h"
#include "config.h"
#include "Polygon.h"

using namespace std;

#endif

最佳答案

只是一些一般性的评论...

 #define PI 3.14159

请使用M_PImath.h , 即 3.141592653589793238462643。

#include "\include\hge.h"
#include "\include\hgesprite.h"
#include "\include\hgefont.h"
#include "\include\hgeparticle.h"
#include "\include\hgerect.h"

您应该使用正斜杠 /在这里,并删除领先的 \include 之前.

using namespace std;

在头文件中避免这种情况。这会污染所有其他用户的全局命名空间。 (因此,您应该在 std::list<hgeVector> vertices; 中使用 Polygon.h。)

关于c++ - 尝试在 C++ 中使用列表时编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2396750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com