|
-
October 27th, 2011, 03:42 PM
#2
Re: MFC CTypedPtrList in a CTypedPtrList error
 Originally Posted by Baldric7202
I can not see what is wrong, can nayone else?
To see what is wrong, you need to go into the MFC code where the error is generated (go to the Output Window and click on the line where the error originates).
It is an error because of this:
Code:
POSITION AddTail(TYPE newElement)
{ return BASE_CLASS::AddTail(newElement); }
This is in afxtempl.h. In your case BASE_CLASS is a CPtrList. Now let's look at AddTail for CPtrList:
Code:
// add before head or after tail
POSITION AddTail(void* newElement);
void AddTail(CPtrList* pNewList);
It is overloaded. The second overload is used if the item to add is a pointer to a CPtrList, or if the compiler finds that this overload is the best match for the function. This overload returns void, and that is where your problem starts.
Note that return type is not considered by the compiler when given two overloaded functions and the compiler must choose which one is the best match. There is an overload version of AddTail in CTypedPtrList:
Code:
void AddTail(CTypedPtrList<BASE_CLASS, TYPE>* pNewList)
{ BASE_CLASS::AddTail(pNewList); }
But again, return type is not considered when the compiler is doing its lookup for the best matching function. So the compiler doesn't match up "void" with "void", only that argument you're giving AddTail(). I won't even go through the maze of intermal MFC code as to why the compiler matches the POSITION AddTail() to the void AddTail() and gives the error, but that's the reason for the error.
So either you set up your list's differently, or you can use std::list. To be honest with you, it looks like you're overcomplicating something that should be simple. What exactly are you trying to accomplish with all of these pointers? In this day and age of C++, coding like this is really not necessary.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; October 27th, 2011 at 04:15 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|