STL 复制在"typedef"类型的数组上失败
STL copy failed on array of 'typedef' type
平台:MinGW64(ruenvb 4.7.2(,Windows 7(64(,Qt 4.8.2
给定代码段如下:
/* type definition */
typedef long T_PSIZE;
struct A { T_PSIZE myArray[10]; };
struct B { T_PSIZE myArray[10]; };
/* declare variable */
A a;
B b;
std::copy(a.myArray[0], a.myArray[10], &b.myArray);
我不知道编译器为什么会抛出以下错误消息(当从"typedef long t_PSIZE;"更改为"type def int t_PSIZEs;"时也会显示类似的消息(:
> c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:
> In instantiation of '_OI std::__copy_move_a(_II, _II, _OI) [with bool
> _IsMove = false; _II = long int; _OI = long int (*)[9]]': c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:422:39:
> required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool
> _IsMove = false; _II = long int; _OI = long int (*)[9]]' c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:454:18:
> required from '_OI std::copy(_II, _II, _OI) [with _II = long int; _OI
> = long int (*)[9]]' ..InfluSimHKPrototypeSimApplication.cpp:114:36: required from here
> c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:375:57:
> error: no type named 'value_type' in 'struct std::iterator_traits<long
> int>'
> c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:377:64:
> error: no type named 'iterator_category' in 'struct
> std::iterator_traits<long int>'
> c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:381:57:
> error: no type named 'value_type' in 'struct std::iterator_traits<long
> int>'
> c:mingwrubenvb-4.7.2-64bin../lib/gcc/x86_64-w64-mingw32/4.7.2/../../../../include/c++/4.7.2/bits/stl_algobase.h:384:70:
> error: no type named 'iterator_category' in 'struct
> std::iterator_traits<long int>'
编译器的模板引擎似乎无法识别类型"long int"。我在"普通int"数组中使用了类似的语句,效果很好。我没有使用任何STL容器,因为我确切地知道目标数组的大小,所以我认为我不需要重新实现类似back_inserter的东西。我错过什么了吗?
注意:我不确定这个问题是否有帮助。(或者,我如何才能获得语句的"完整"限定名来处理typedef-ed变量?(
您的意思可能是:
std::copy(&a.myArray[0], &a.myArray[10], &b.myArray[0]);
或
std::copy(a.myArray, a.myArray + 10, b.myArray);
a.myArray[0]
只是long
,而不是std::copy
所需的指向long
数组的指针。此外,输出参数的类型需要与要复制的对象的类型兼容。&b.myArray
具有类型long (*)[10]
,而您需要提供类型long*
的参数。
相关文章:
- 从父数组测试用例构造二叉树失败
- 结构化绑定初始值设定项表单 { 赋值表达式 } 对于 clang 上的数组类型失败
- 用于查找连续子数组的最大总和的代码使测试用例失败
- 分段失败反向数组
- Lambda 捕获数组元素失败
- UINT8数组对INT64的质量化失败,但应该起作用
- 简单的2D数组标头文件,打印失败
- constexpr + 多维数组失败
- 从 3D 数组转换为 1D 数组失败
- 十六进制数组 cout 到文本文件失败
- 动态分配缓冲空间为二维数组 - 为什么失败
- 删除数组时断言失败
- c++ sort() 函数对于<algorithm>整数数组的大小(元素数)>10^7 个元素的大输入是否失败?
- 返回指向指针数组的指针获取下一个元素失败
- 对象的c++数组,初始化失败
- C++类模板构造函数 -- 重载引用 (U&) 与数组 (U*) 失败
- 检索静态char*数组失败
- Qt Qvariantlist转换为javascript数组失败
- 动态分配对象数组失败
- BOOST/CSTDINT类型BOOST稀疏向量数组失败,为什么