c++ - 'std::vector' : 'U64' is not a valid template type argument for parameter '_Ty'

标签 c++ templates vector compiler-errors

我有一个头文件SomeDefines.h,其中包括

#define U64 unsigned long long
#define U16 unsigned short

在Myclass.h中,我在顶部#include SomeDefines.h

在Myclass声明中,我有一个函数
bool someFunc(const std::vector<U64>& theVector);

和一个成员变量
tbb::atomic someNumber;

在Visual Studio 2012中进行编译时,出现错误
error: 'U64': undeclared identifier
error C2923: 'std::vector': 'U64' is not a valid template type argument for parameter '_Ty'

如果我将U64替换为unsigned long long,错误就会消失
bool someFunc(const std::vector<unsigned long long>& theVector);

我以为编译器会看到#define U64 unsigned long long并将U64替换为unsigned long long

为什么我收到U64而不是U16的这些错误?

最佳答案

#define不是创建新类型的好主意。首选typedefusing:

typedef unsigned long long U64;
// or:
using U64 = unsigned long long;

关于c++ - 'std::vector' : 'U64' is not a valid template type argument for parameter '_Ty' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28485960/

相关文章:

c++ - 计算两个已知大小和位置的物体之间的碰撞

c++ - 格式错误的调用的零长度可变参数扩展

actionscript-3 - ActionScript - 比较和删除复杂数组的重复项?

c++ - 在指向对象的指针 vector 中取消引用

c++ - 将数组传递给增强 vector 元组

C++如何使用动态库(.so文件)

c++ - 使用可变参数模板作为属性

C++模板语法错误

c++ - 播放 .wav 文件

c++ - Enterprise Architect 中的模型模板功能