【发布时间】:2021-09-12 07:47:09
【问题描述】:
使用 TI Code Composer 为 MSP430 编译以下 C++14 代码时出现以下错误:
subdir_rules.mk:14:目标“main.obj”的配方失败 “Interface.h”,第 75 行:错误 #18:应为“)” “Derived.h”,第 91 行:错误 #18:预期为“)”这适用于以下代码结构,其中Interface.h 类是一个可以为 STM32 目标编译良好的库。
#include <cstdint>
namespace NS
{
class Interface
{
public:
// Other pure virtual functions such as:
virtual void advance() = 0;
// This is the problem function
virtual void advance(const uint32_t N) = 0;
};
}
接下来在 MSP430 项目中,该接口用于多个对象。这是多个实现的一个示例,它们都给出相同的错误。
#include "Interface.h"
class Derived : public ::NS::Interface
{
public:
// Overriding virtual functions with implementations in cpp file.
void advance() override;
// The problematic function
void advance(const uint32_t N) override;
private:
uint32_t index;
};
cpp 文件:
#include "Derived.h"
Derived::advance()
{
++index;
}
Derived::advance(const uint32_t N)
{
index += N;
}
现在检查代码中的任何“有趣”字符(如希腊问号)都没有产生任何结果。我尝试替换文本,再次输入等等,没有结果
注释掉函数 advance(const uint32_t N) 解决了问题,因此它不是文件中的其他内容。
什么可能导致这个问题?
【问题讨论】:
-
你是
#include <stdint.h>还是uint32_t?请告诉我们minimal reproducible example,而不仅仅是摘录。 -
@thebusybee 好点,在原文中包含,将其添加到问题中。
-
如果您使用
#include <cstdint>(而不是#include <stdint.h>),您应该使用像std::uint32_t这样的限定名称,因为C++ 标准不要求这些名称在全局命名空间IIRC 中可用。 -
@heapunderrun 我明白你的意思。我不明白的是
Interface中uint8_t的其他功能怎么可能没有同样的问题。在Deriveduint32_t作为变量使用没有任何问题。 -
错误信息参考 Interface.h 中的第 75 行和 Derived.h 中的第 91 行。指出这些行号指的是哪一个。然而,可能的罪魁祸首是出现在这些行之前的任何内容,使编译器期望一个右括号 - 包括错误行之前的任何嵌套包含中的错误。