'typedef'类型的数组上的STL复制失败

Yam*_*HAN 0 c++ stl-algorithm

平台:MinGW64(rubenvb 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);
Run Code Online (Sandbox Code Playgroud)

我不知道为什么编译器抛出以下错误消息(当从'typedef long T_PSIZE''更改为'typedef int T_PSIZE'时,也会显示类似的消息):

> c:\mingw\rubenvb-4.7.2-64\bin\../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:\mingw\rubenvb-4.7.2-64\bin\../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:\mingw\rubenvb-4.7.2-64\bin\../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]]' ..\InfluSimHKPrototype\SimApplication.cpp:114:36:   required from here
> c:\mingw\rubenvb-4.7.2-64\bin\../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:\mingw\rubenvb-4.7.2-64\bin\../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:\mingw\rubenvb-4.7.2-64\bin\../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:\mingw\rubenvb-4.7.2-64\bin\../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>'
Run Code Online (Sandbox Code Playgroud)

似乎编译器的模板引擎无法识别类型'long int'.我在'普通int'数组中使用了类似的语句,效果很好.我没有使用任何STL容器,因为我完全知道目标数组的大小,所以我认为我不需要重新实现像back_inserter这样的东西.我错过了什么吗?

:我不知道如果这个问题是这样的帮助.(或者我怎样才能获得声明的'完整'限定名称来处理typedef-ed变量?)

CB *_*ley 6

你可能意味着:

std::copy(&a.myArray[0], &a.myArray[10], &b.myArray[0]);
Run Code Online (Sandbox Code Playgroud)

要么

std::copy(a.myArray, a.myArray + 10, b.myArray);
Run Code Online (Sandbox Code Playgroud)

a.myArray[0]仅仅是一个long,而不是一个指针的阵列long,其std::copy需要.此外,输出参数的类型需要与要复制的对象的类型兼容.&b.myArray有类型,long (*)[10]而你需要提供类型的参数long*.