c++ - 使用 g++ 编译时出现多个错误?
问题描述
编译我的代码时,我收到许多不同的错误,例如:
frame.h:5:48: error: expected identifier before '(' token
frame.h:5:17: error: variable or field 'writeFrame' declared void
frame.h:5:17: error: 'GifWriter' was not declared in this scope
frame.h:5:34: error: expected primary-expression before 'double'
这些错误或多或少适用于所有函数参数。
这是头文件:
#ifndef frame_h
#define frame_h
void writeFrame(GifWriter* gptr, double delay, (std::vector<uint8_t>& frameOut), ImageData* image1ptr, struct Options mode, int frameNum, bool* runptr);
void runPRGM(ImageData* image1ptr, struct Options mode);
#endif
我的 .cpp 文件确实包含所需的库和这个 .h 文件,并且这两个函数的声明方式相同。我确定括号和括号已正确解析。除了 .cpp 中的函数定义之外,这些是函数声明的唯一实例。我可能做错了什么?我确实在其他一些线程中读到 g++ 也与某些 void 函数发生冲突,但对此没有太多详细说明。
解决方案
更改(std::vector<uint8_t>& frameOut)
为std::vector<uint8_t>& frameOut
。
不知道为什么你觉得需要把括号放在那里,第一条错误消息告诉你这就是问题所在。
另请注意,您应该编写头文件,以便它们是自包含的。这意味着这个头文件应该具有#include <vector>
以及声明GifWriter
等。如果情况合适,这些可能是前向声明。
所以标题应该看起来像这样
#ifndef frame_h
#define frame_h
#include <vector> // for vector
#include <cstdint> // for uint8_t
class GifWriter; // forward declarations
class ImageData;
struct Options;
void writeFrame(GifWriter* gptr, double delay, std::vector<uint8_t>& frameOut, ImageData* image1ptr, Options mode, int frameNum, bool* runptr);
void runPRGM(ImageData* image1ptr, Options mode);
#endif
图片假设GifWriter
和是您ImageData
编写Options
的类,因此可以安全地转发声明它们。如果没有,那么您应该在此处包含这些类的头文件。
推荐阅读
- python - 使用 ExecuteScript 和 Python 将 JSON 写入文件
- javascript - 没有重载匹配此调用 Typescript on Button in React native
- javascript - 级联下拉asp.net MVC
- angular - 使用角度保护 Laravel 中的路线
- python - 由于 node-gyp 无法安装节点模块
- python-3.x - python3希腊字母未正确显示
- python - 如何解密最初使用 Fernet 加密的不同服务上的值?
- python - 在 3D 数组中查找最大值时间
- python - 如何动态循环值以过滤熊猫数据框?
- oracle - 如何在 Oracle 中将 UTF-16 符号代码转换为 nvarchar2?