The information in this article applies to:
SUMMARY
When you write an application with the CObList class provided by the
Microsoft Foundation Class (MFC) libraries, you may note that many of the
member functions have both const and non-const forms. For example, the
CObList class has two GetNext() member functions, as follows:
The first form of the GetNext() member function is for non-const CObList objects and implements the left-side of the assignment operator. The second form of the GetNext() member function is used when the CObList object is const (generally, this means that you are using a pointer to a const CObList to prevent any modification to the contents of the CObList). Note that the first member function returns a reference to a CObject pointer. The item returned is the actual CObject pointer in the list, not its value. Through this reference, you can modify the CObject pointer and use the return value of the member function to modify the list. The second member function does not provide access to modify the CObList. MORE INFORMATION
The code sample below demonstrates using the GetNext() member function that
returns a reference to a CObject pointer. Note the comment in the code. If
you remove the comment from the indicated line, an error results.
Sample Code
* Compiler options needed: Visual C++ 4.0 - /MT[d] or /MD[d]
* Others - None
class CMyObject: public CObject { public:
} MyObject(2); // Create a CObject to place in the CObList.
{
cout << ((CMyObject*)pMyList->GetNext(p))->set;
(pMyList->GetNext(p)) = &MyObject;
cout << ((CMyObject*)pMyList->GetNext(p))->set;} Additional query words: 7.00 1.00 1.50 2.00 2.10 2.50 2.51 2.52 3.00 kbinf 4.00
Keywords : kbMFC kbVC100 kbVC150 kbVC200 kbVC400 kbGrpMFCATL kbCollectionClass |
Last Reviewed: November 25, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |