Compiler Error

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
 
D

David Wilkinson

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");
 
J

jc

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");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top