I have a definition:

DM_ComponentStatusType m_aeComponentStatusTypes[14];

in which DM_ComponentStatusType is a C++ structure. I'm trying to fill
another structure in which one of the elements is defined as:

DM_ComponentStatusType* pStatusTypes[14];

When I code this line:

psMaintenanceComponentEvent->pStatusTypes =
&theApp.m_aeComponentStatusTypes;

I get the following compile error that I can't figure out. Can anyone tell
me what I'm doing wrong (and why :-) Thanks!

sralogger.cpp(92) : error C2440: '=' : cannot convert from
'DM_ComponentStatusType (*)[14]' to 'DM_ComponentStatusType *[14]'
There are no conversions to array types, although there are
conversions to references or pointers to arrays

Re: C2440 error by Victor

Victor
Tue May 10 20:15:22 CDT 2005

Larry Waibel wrote:
> I have a definition:
>
> DM_ComponentStatusType m_aeComponentStatusTypes[14];
>
> in which DM_ComponentStatusType is a C++ structure. I'm trying to
> fill another structure in which one of the elements is defined as:
>
> DM_ComponentStatusType* pStatusTypes[14];
>
> When I code this line:
>
> psMaintenanceComponentEvent->pStatusTypes =
> &theApp.m_aeComponentStatusTypes;
>
> I get the following compile error that I can't figure out. Can
> anyone tell me what I'm doing wrong (and why :-) Thanks!
>
> sralogger.cpp(92) : error C2440: '=' : cannot convert from
> 'DM_ComponentStatusType (*)[14]' to 'DM_ComponentStatusType *[14]'
> There are no conversions to array types, although there are
> conversions to references or pointers to arrays

Arrays are not assignable in C++. If you mean to set every element in
'psMaintenanceComponentEvent->pStatusTypes' to be a pointer to the
respective element of 'theApp.m_aeComponentStatusTypes', you have to
do it using a loop of some kind.

V



Re: C2440 error by Eugene

Eugene
Wed May 11 02:10:06 CDT 2005

> Larry Waibel wrote:
>> I have a definition:
>>
>> DM_ComponentStatusType m_aeComponentStatusTypes[14];

This is an array of 14 DM_ComponentStatusType

>> in which DM_ComponentStatusType is a C++ structure. I'm trying to
>> fill another structure in which one of the elements is defined as:
>>
>> DM_ComponentStatusType* pStatusTypes[14];

And this is an array of 14 pointers to DM_ComponentStatusType.

>> When I code this line:
>>
>> psMaintenanceComponentEvent->pStatusTypes =
>> &theApp.m_aeComponentStatusTypes;

so you are asking to assign an address of array of 14 DM_ComponentStatusType
to an array of 14 pointers to DM_ComponentStatusType. Which is nonsense.

>> I get the following compile error that I can't figure out. Can
>> anyone tell me what I'm doing wrong (and why :-) Thanks!
>>
>> sralogger.cpp(92) : error C2440: '=' : cannot convert from
>> 'DM_ComponentStatusType (*)[14]' to 'DM_ComponentStatusType *[14]'

And the message says exactly this: cannot convert from an address of array
of 14 DM_ComponentStatusType to an array of 14 pointers to
DM_ComponentStatusType.

What you probably want to do is either this

for(int i = 0; i != 14; ++i)
{
psMaintenanceComponentEvent->pStatusTypes[i] =
&(theApp.m_aeComponentStatusTypes[i]);
}

*Or*

declare pStatusTypes as

DM_ComponentStatusType (* pStatusTypes)[14];

This declares a pointer to array so that your line

psMaintenanceComponentEvent->pStatusTypes =
&theApp.m_aeComponentStatusTypes;

becomes valid.

--
Eugene
http://www.gershnik.com



Re: C2440 error by Larry

Larry
Wed May 11 09:33:54 CDT 2005

Ahhhh, I see; thanks!

In article <uqFIobcVFHA.2572@TK2MSFTNGP14.phx.gbl>, Victor Bazarov wrote:
> Arrays are not assignable in C++. If you mean to set every element in
> 'psMaintenanceComponentEvent->pStatusTypes' to be a pointer to the
> respective element of 'theApp.m_aeComponentStatusTypes', you have to
> do it using a loop of some kind.
>



Re: C2440 error by Larry

Larry
Wed May 11 09:33:59 CDT 2005

Yep, I see now; thanks!

In article <OMJrzhfVFHA.3076@TK2MSFTNGP10.phx.gbl>, Eugene Gershnik wrote:
> so you are asking to assign an address of array of 14 DM_ComponentStatusType
> to an array of 14 pointers to DM_ComponentStatusType. Which is nonsense.
>