HighTechTalks DotNet Forums  

Compiler Error

VC++.net microsoft.public.dotnet.languages.vc


Discuss Compiler Error in the VC++.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
jc
 
Posts: n/a

Default Compiler Error - 12-20-2008 , 03:55 PM






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[i]).strResult = _T("3");

Any suggestion on how to fix the code?

TIA;
-jc

Reply With Quote
  #2  
Old   
David Wilkinson
 
Posts: n/a

Default Re: Compiler Error - 12-21-2008 , 06:03 AM






jc wrote:
Quote:
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[i]).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)[i])->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[i]->strResult = _T("3");

--
David Wilkinson
Visual C++ MVP


Reply With Quote
  #3  
Old   
jc
 
Posts: n/a

Default Re: Compiler Error - 12-21-2008 , 10:17 AM



David,

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

0jc

"David Wilkinson" wrote:

Quote:
jc wrote:
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[i]).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)[i])->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[i]->strResult = _T("3");

--
David Wilkinson
Visual C++ MVP


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.