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

    why const CString & host cannot use the GetBuffer() function?

    why const CString & host cannot use the GetBuffer() function?

    code:
    if(inet_addr( host.GetBuffer(0) )==INADDR_NONE)
    { .....}
    error:
    C2663: “ATL::CSimpleStringT<BaseType>::GetBuffer” : 2 个重载没有“this”指针的合法转换
    with
    [
    BaseType=TCHAR
    ]
    help me , thanks!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: why const CString & host cannot use the GetBuffer() function?

    2 个重载没有“this”指针的合法转换
    Could you translate it?

  3. #3
    Join Date
    Jul 2002
    Posts
    2,543

    Re: why const CString & host cannot use the GetBuffer() function?

    Cast to const pointer:
    Code:
    if(inet_addr( (LPCTSTR)host.GetBuffer(0) )==INADDR_NONE)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: why const CString & host cannot use the GetBuffer() function?

    Quote Originally Posted by Alex F
    Cast to const pointer:
    Code:
    if(inet_addr( (LPCTSTR)host.GetBuffer(0) )==INADDR_NONE)
    Hmm, in this case you do NOT need GetBuffer() at all!:
    Code:
    if(inet_addr( (LPCTSTR)host)==INADDR_NONE)

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: why const CString & host cannot use the GetBuffer() function?

    I see even the cast (LPC[T]STR) is not needed. The CString:perator LPCTSTR() will be invoked as "conversion" operator automatically.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  6. #6
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: why const CString & host cannot use the GetBuffer() function?

    You simply can't call GetBuffer(), because GetBuffer() is not a const method, and since your object is const, you can't. For objects that are declared as const, you can only call constant member functions. This ensures that the constant object is never modified.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  7. #7
    Join Date
    Apr 2005
    Posts
    4

    Re: why const CString & host cannot use the GetBuffer() function?

    2 个重载没有“this”指针的合法转换
    means two overloadings don't have "this"pointer's legal conversion

    I see ,thank you very much!

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