uint8_t 和 unsigned char 链接错误

发布于 2024-10-09 18:54:52 字数 873 浏览 0 评论 0原文

我正在使用模板函数:

template<typename T> void func(const T& value)
{
    obj->func(value);
}

其中 obj 是类的对象:

void my_object::func(int64_t value) { ... }
void my_object::func(uint64_t value) { ... }
void my_object::func(uint32_t value) { ... }
void my_object::func(uint16_t value) { ... }
void my_object::func(uint8_t value) { ... }

问题在于 my_object::func() 重写的 uint8_t 重载。链接器抱怨重载无法解析的外部符号,该重载应该具有unsigned char参数。

我应该用 unsigned char 重载替换 uint8_t 重载吗?

编辑:刚刚注意到,该链接器也抱怨 uint64_tint64_t

我使用 MSVC++ 2008 Express 在 Windows 上进行编译。

编辑:抱歉,我声明 my_object::func(uint8_t value) 函数(和其他),但我没有定义它。

I'm using template function:

template<typename T> void func(const T& value)
{
    obj->func(value);
}

where obj is object of class:

void my_object::func(int64_t value) { ... }
void my_object::func(uint64_t value) { ... }
void my_object::func(uint32_t value) { ... }
void my_object::func(uint16_t value) { ... }
void my_object::func(uint8_t value) { ... }

The problem is with uint8_t overload of my_object::func() override. Linker complains about unresolved external symbols to overloads, which should have unsigned char parameter.

Should I replace uint8_t overload with unsigned char overload?

Edit: Just now noticed, that linker complains about uint64_t and int64_t too.

I compile on Windows using MSVC++ 2008 Express.

Edit: Apologies, I declared my_object::func(uint8_t value) function (and other), but I didn't defined it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

睫毛溺水了 2024-10-16 18:54:52

这是 include 文件应该 #include 以使用上述类型(C99 建议)

#include

This is the include file should #include to use the above mentioned types (C99 recommendations)

#include <stdint.h>

行雁书 2024-10-16 18:54:52

我猜测 uint8_t 已被 typedef 编辑为 unsigned char,因此您会看到这一点。

I'm guessing that uint8_t has been typedefed as unsigned char, hence why you're seeing that.

‘画卷フ 2024-10-16 18:54:52

尝试编译并

template void my_object::func(int64_t value) { ... }
template void my_object::func(uint64_t value) { ... }
template void my_object::func(uint32_t value) { ... }
template void my_object::func(uint16_t value) { ... }
template void my_object::func(uint8_t value) { ... }

修复我的类似问题

Try compiling with

template void my_object::func(int64_t value) { ... }
template void my_object::func(uint64_t value) { ... }
template void my_object::func(uint32_t value) { ... }
template void my_object::func(uint16_t value) { ... }
template void my_object::func(uint8_t value) { ... }

fixed my problem with a similar issues

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文