错误错误C2143:语法错误:缺少';'前“”
问题描述:
你好我写一个IOManager,但我得到这个错误:错误错误C2143:语法错误:缺少';'前“<class-head>”
Error 1 error C2143: syntax error : missing ';' before '<class-head>'
我的代码是这样的:
#pragma once
#include <vector>
class IOManager{
public:
static bool readFileToBuffer(std::string filePath, std::vector<unsigned char>& buffer);
};
我不知道我做错了什么!
答
您使用std::string
,但不包括<string>
标题。该行添加到顶部:
#include <string>
所以您将获得:
#pragma once
#include <string>
#include <vector>
class IOManager{
public:
static bool readFileToBuffer(std::string filePath, std::vector<unsigned char>& buffer);
};
它应该工作。
答
嘿我明白这已经回答了,但对于其他人谁谈到过去的这一点,
我会透过YouTube的教程,可能你有相同的一个,同时得到了同样的错误。我做了#include <string>
,但它并没有解决我的错误。原来,从单独的文件(picoPNG.h)的最后一行来到了错误:
#pragma once
#include <vector>
extern int decodePNG(std::vector<unsigned char>& out_image, unsigned long& image_width, unsigned long& image_height, const unsigned char* in_png, size_t in_size, bool convert_to_rgba32 = true)
我有什么做的是包括最后一行后的分号所以它结束了:
#pragma once
#include <vector>
extern int decodePNG(std::vector<unsigned char>& out_image, unsigned long& image_width, unsigned long& image_height, const unsigned char* in_png, size_t in_size, bool convert_to_rgba32 = true);
本导师最终修复这个bug在后面的教程中为我。所以试着看看你的其他头文件,看看有没有分号的地方。
希望这有助于某人!
答
我在我的C++代码中获得了此代码虚幻引擎。 这是因为我在头文件(.h)文件中的类声明 的末尾忘了分号。
class MyClass{
private: //Stuff here
public: //Stuff here
}; //<--------DONT FORGET THE SEMICOLON
即使您使用的是“std :: string”,您也没有'#include' –
NathanOliver