CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 1999
    Posts
    42

    URGENT - template problem - PLEASE HELP

    Throughout my project I use class members of type CMap e.g.:
    CMap<CString, LPCSTR, C_ApplicationPart*, C_ApplicationPart*> m_mapApplicationPart;

    Until yesterday the compiler accepted these constructions. But suddenly it reports the following error for every CMap type defined:
    C:\Program Files\DevStudio\VC\MFC\include\afxtempl.h(1478) : error C2664: 'SetAt' : cannot convert parameter 1 from 'const char *' to 'class CString &'

    This is very odd.... I've reversed changes I've made, tried old project/workspace files but nothing seems to work. I created a testproject and this project compiles CMap<CString, LPCSTR, typeVal, typeArg> with no problems!!!!

    I also tried deleting all temporary files and precompiled header files but nothing seems to work.

    Please, please help!

    Martin van den Berg
    [email protected]


  2. #2
    Join Date
    Apr 1999
    Posts
    9

    Re: URGENT - template problem - PLEASE HELP

    just guess:
    the error is raised by SetAt() not by CMap<...> constructor

    check the SetAt(), maybe you use
    CString str;
    SetAt(str, ....);
    but not
    SetAt((LPCTSTR)str, ....);

    just guess...


  3. #3
    Join Date
    Apr 1999
    Posts
    42

    Re: URGENT - template problem - PLEASE HELP

    The compile error occures in
    afxtempl.h in the CMap::Serialize method which I do not even use!!!

    I am confinced it is not in on of my projects SetAt()'s.

    Martin van den Berg
    High Tech Automation
    The Netherlands
    [email protected]

  4. #4
    Join Date
    Apr 1999
    Posts
    306

    Re: URGENT - template problem - PLEASE HELP

    This error means that you are giving an argument of class CString to SetAt(char *) which actually takes parameter of type (char *).

    Try with the CSTring member operator as well
    operator LPCTSTR ( ) const;
    which converts the CString to a C-string

    This casting operator provides an efficient method to access the null-terminated C string contained in a CString object. No characters are copied; only a pointer is returned. Be careful with this operator. If you change a CString object after you have obtained the character pointer, you may cause a reallocation of memory that invalidates the pointer.

    Or just try extracting the CString values into a buffer of type (char *) and then give it to the function SetAt(buffer); but I think the first is better and faster.


  5. #5
    Join Date
    Apr 1999
    Posts
    42

    Re: URGENT - template problem - PLEASE HELP

    My problem goes beyond casting etc..
    The problem is that the compiler reports an error in CMap::Serialize(). In this method the SetAt method is used and this is where the compiler complains about.

    I commented this particular piece of code in afxtempl.h out and it now compiles fine! Ofcourse this is a big HACK but it works for the mean time.

    I didn't make any mistakes - have a look at the sample in 'Collections: Template-Based Classes.:


    Martin van den Berg
    High Tech Automation
    The Netherlands
    [email protected]

  6. #6
    Join Date
    Apr 1999
    Posts
    383

    Re: URGENT - template problem - PLEASE HELP

    That code ought to be OK.

    The CMap::SetAt method expects parameter 1 to be an ARG_KEY type, which you've declared to be LPCSTR. The CMap::Serialize method is passing it a CString, which should convert OK (CString has an LPTCSTR conversion).

    The error message says SetAt is expecting a CString&, but is getting passed a const char*, which is obviously not correct - it's the reverse of what you'd expect.

    I think that somewhere in your program you have mistakenly defined a CMap with the first two template arguments reversed:

    CMap<LPCSTR, CString&, C_ApplicationPart*, C_ApplicationPart*> m_mapApplicationPart;

    If you put this into your test program it should give the same error.

    Nothing else seems to make sense...

    Dave



  7. #7
    Join Date
    Apr 1999
    Posts
    42

    SOLUTION

    Dave,

    Thanks! That was exactly it!!



    Martin van den Berg
    High Tech Automation
    The Netherlands
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured