Compiler Error

  • Thread starter Thread starter jc
  • Start date Start date
J

jc

Hello,

CPtrArray *pArrTable;
CPtrArray m_pArrTable

pArrTable = &m_pArrTable;

I'm getting a compiler error from the following line of code:

(*(PTABLE_INFO_STRUCT)pArrTable).strResult = _T("3");

Any suggestion on how to fix the code?

TIA;
-jc
 
jc said:
Hello,

CPtrArray *pArrTable;
CPtrArray m_pArrTable

pArrTable = &m_pArrTable;

I'm getting a compiler error from the following line of code:

(*(PTABLE_INFO_STRUCT)pArrTable).strResult = _T("3");

Any suggestion on how to fix the code?


jc:

You need to dereference pArrTable before you can apply operator[]. Also, you do
not ned to dereference to access a member of a class or struct; you can use the
-> notation.

((PTABLE_INFO_STRUCT)(*pArrTable))->strResult = _T("3");

But really, why are you using CPtrArray? Or the MFC collection classes at all
really. Just learn the STL containers instead

std::vector<PTABLE_INFO_STRUCT> arrTable;
//...
arrTable->strResult = _T("3");
 
David,

Thanks for the solution, and also for the suggestion to learn STL.
STL looks a lot less complicated.

0jc

David Wilkinson said:
jc said:
Hello,

CPtrArray *pArrTable;
CPtrArray m_pArrTable

pArrTable = &m_pArrTable;

I'm getting a compiler error from the following line of code:

(*(PTABLE_INFO_STRUCT)pArrTable).strResult = _T("3");

Any suggestion on how to fix the code?


jc:

You need to dereference pArrTable before you can apply operator[]. Also, you do
not ned to dereference to access a member of a class or struct; you can use the
-> notation.

((PTABLE_INFO_STRUCT)(*pArrTable))->strResult = _T("3");

But really, why are you using CPtrArray? Or the MFC collection classes at all
really. Just learn the STL containers instead

std::vector<PTABLE_INFO_STRUCT> arrTable;
//...
arrTable->strResult = _T("3");
 
Back
Top