If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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:

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.

Re: MFC CTypedPtrList in a CTypedPtrList error

Paul,

Thanks for the reply, it confirms the conclusion I came to about an hour after I posted the question. In the end I have ended up with an CTypedPtrArray as the outer list, less efficient for what I need, I may change it to a simple CPtrList later. We use the CTypedPtrArray/List as we have derrived classes that automatically delete the objects when they are removed from the list.

The reason for the 2 lists is because we have a list of rleated tasks passed from the front end or remote clients, these are added to a queue, the outer list, for the backend to handle.