|
-
July 21st, 2009, 11:00 AM
#1
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 * ?
-
July 21st, 2009, 11:21 AM
#2
Re: const can't be assigned to non const?
 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.
 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?
-
July 21st, 2009, 12:06 PM
#3
Re: const can't be assigned to non const?
 Originally Posted by homer_3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|