0

平台: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);

我不知道为什么编译器会抛出以下错误消息(从 '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>'

编译器的模板引擎似乎无法识别类型“long int”。我将类似的语句与“普通整数”数组一起使用,效果很好。我没有使用任何 STL 容器,因为我确切地知道目标数组的大小,所以我认为我不需要重新实现类似 back_inserter 的东西。我错过了什么吗?

注意:我不确定这样的问题是否有帮助。(或者我怎样才能获得语句的“完整”限定名称以处理 typedef ed 变量?)

4

1 回答 1

6

你可能的意思是:

std::copy(&a.myArray[0], &a.myArray[10], &b.myArray[0]);

或者

std::copy(a.myArray, a.myArray + 10, b.myArray);

a.myArray[0]只是一个long,而不是指向需要数组的long指针std::copy。此外,输出参数的类型需要与被复制对象的类型兼容。&b.myArray具有类型long (*)[10],而您需要提供类型的参数long*

于 2013-02-26T08:31:00.380 回答