MFC CMap Problems
-
:confused:I am stumped by the following. My application uses a lot of CMap's, about a dozen or so so far to store pointers, strings etc. I just tried to add the following: ----------------------------------------------------------- Test.h class CCMyClass : public CWnd { protected: DECLARE_MESSAGE_MAP() public: CCMyClass(); virtual ~CCApp_Menu(); typedef CMap, mapTest; protected: mapTest* p_Map; In the implementation, it is the standard yada, yada that Developer Studio put in then you add a class. In the constructor, we have: CMap p_Map = new mapTest; The next thing that it does is basically as follows: p_struct = new MyStruct; //MyStruct defined elsewhere .... Add data to structure here and store in map. p_Map->SetAt(n, p_struct); After I map a bunch of p_structs's, it then gets interesting. When I go to iterate the map at a later time: ......... POSITION pos = p_Map->GetStartPosition(); int nCount() = p_Map->GetCount(); // nCount is Correct //pos = 0xffffff!! Which is of course a problem! It is failing in afxtempl.h at: template AFX_INLINE POSITION CMap::GetStartPosition() const { return (m_nCount == 0) ? NULL : BEFORE_START_POSITION; } I have tried to create the map in other classes, some which have CMap's like the above that work correctly, however I get the same result. Everything else works fine. Other info: Developer Studio 7.0 Windows XP Dual AMD processors 1 Gb. RAM All current updates. No memory leaks? It is almost as if Windows will only allow a given amount of CMap's at any given time. Is that true? Has anyone else run into this? Work around? Any input is appreciated! Barry Barry
-
:confused:I am stumped by the following. My application uses a lot of CMap's, about a dozen or so so far to store pointers, strings etc. I just tried to add the following: ----------------------------------------------------------- Test.h class CCMyClass : public CWnd { protected: DECLARE_MESSAGE_MAP() public: CCMyClass(); virtual ~CCApp_Menu(); typedef CMap, mapTest; protected: mapTest* p_Map; In the implementation, it is the standard yada, yada that Developer Studio put in then you add a class. In the constructor, we have: CMap p_Map = new mapTest; The next thing that it does is basically as follows: p_struct = new MyStruct; //MyStruct defined elsewhere .... Add data to structure here and store in map. p_Map->SetAt(n, p_struct); After I map a bunch of p_structs's, it then gets interesting. When I go to iterate the map at a later time: ......... POSITION pos = p_Map->GetStartPosition(); int nCount() = p_Map->GetCount(); // nCount is Correct //pos = 0xffffff!! Which is of course a problem! It is failing in afxtempl.h at: template AFX_INLINE POSITION CMap::GetStartPosition() const { return (m_nCount == 0) ? NULL : BEFORE_START_POSITION; } I have tried to create the map in other classes, some which have CMap's like the above that work correctly, however I get the same result. Everything else works fine. Other info: Developer Studio 7.0 Windows XP Dual AMD processors 1 Gb. RAM All current updates. No memory leaks? It is almost as if Windows will only allow a given amount of CMap's at any given time. Is that true? Has anyone else run into this? Work around? Any input is appreciated! Barry Barry
I use the CMap in a very similar fashion without problems. I did not copy your code to see what may be giving you the problem but thought I'd throw out my two cents: Change your code in the constructor from: CMap p_Map = new mapTest; to: mapTest *p_Map = new mapTest; You may have already done that but if not, it may be worth a shot. My CMap(s) are built with VC6, Win2k.
-
I use the CMap in a very similar fashion without problems. I did not copy your code to see what may be giving you the problem but thought I'd throw out my two cents: Change your code in the constructor from: CMap p_Map = new mapTest; to: mapTest *p_Map = new mapTest; You may have already done that but if not, it may be worth a shot. My CMap(s) are built with VC6, Win2k.
2¢ is appreciated. The code I put in the thread was generic at best. The actual code declares the pointer and creates the object just as you suggested. It should have read: CMap< .......... >* p_Map = new mapTest; I do find it interesting that some people declare pointers as Class *pointer = and some as Class* pPointer. I use the second syntax, as that was the way I was taught. Actually, both work out to the same thing. Thanks again Barry
-
2¢ is appreciated. The code I put in the thread was generic at best. The actual code declares the pointer and creates the object just as you suggested. It should have read: CMap< .......... >* p_Map = new mapTest; I do find it interesting that some people declare pointers as Class *pointer = and some as Class* pPointer. I use the second syntax, as that was the way I was taught. Actually, both work out to the same thing. Thanks again Barry
BarryPearlman wrote: I do find it interesting that some people declare pointers as Class *pointer = and some as Class* pPointer. I use the second syntax, as that was the way I was taught. Actually, both work out to the same thing. I also use the second syntax. Recommended idiom in a C++ context is to use the second way. I also find it easier to read, especially when it comes to declaring reference arguments. However, it's not a big deal and I think it's not something that's pushed in style guides. Kevin