CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    18

    const can't be assigned to non const?

    I'm compiling ACE and get this error value of type "const SSL_METHOD *" can't be assigned to entity of type "SSL_METHOD *". Why won't C/C++ allow assigning a const value to a non const? Any ways to get around this without digging through the code and changing all the methods returning a const SSL_METHOD * to return a SSL_METHOD * ?

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: const can't be assigned to non const?

    Quote Originally Posted by homer_3
    I'm compiling ACE and get this error value of type "const SSL_METHOD *" can't be assigned to entity of type "SSL_METHOD *". Why won't C/C++ allow assigning a const value to a non const?
    Ah, but you are not trying to assign a const value to a non-const object. You are trying to assign a pointer to const to a pointer to non-const.

    Quote Originally Posted by homer_3
    Any ways to get around this without digging through the code and changing all the methods returning a const SSL_METHOD * to return a SSL_METHOD * ?
    Why must you use a pointer to non-const in the first place? Are you calling non-const member functions? If so, does it really, really make sense to call non-const member function in those contexts?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: const can't be assigned to non const?

    Quote Originally Posted by homer_3 View Post
    Why won't C/C++ allow assigning a const value to a non const?
    The fact that you have a const SSL_METHOD * to begin with is a promise to the program that you don't intend to modify the SSL_METHOD that pointer is directed at, at least not via that pointer.

    If you try to assign the address to a non-const pointer, you're essentially trying to weasel your way out of that promise. It's possible, but not wise to do this unless you're absolutely certain it's logical and safe to do so.

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