I get an error when trying to build Loki with VC++9 Express.
<i>3>c:\Users\Alp\Downloads\loki\loki-0.1.7\include\loki/SmartPtr.h(721) : error C3892: 'val' : vous ne pouvez pas assigner une variable const</i>
On this code :
<i> template <class P1>
static P Clone(P1& val)
val = P1();
On the line "val = P1();".
Am I the only one that gets this error ?
A fix ?
Hi Alp Mestan,
I think I discovered why you get the error message. Are you using the SmartPtr class to manage pointers to both const and non-const objects? And then do you use a pointer made for non-const objects to manage a pointer for a const object? I suspect so. I duplicated this problem using the code below.
typedef Loki::SmartPtr< BaseClass, DestructiveCopy, DisallowConversion,
AssertCheck, DefaultSPStorage, DontPropagateConst > NonConst_ptr;
typedef Loki::SmartPtr< const BaseClass, DestructiveCopy, DisallowConversion,
AssertCheck, DefaultSPStorage, DontPropagateConst > Const_ptr;
Const_ptr p1( new BaseClass );
NonConst_ptr p2( p1 );
Please note that the only difference between the two typedef statements is that one has a const object type in the first template parameter, and the other does not.
This code snippet generates this error message:
SmartPtr.h(720) : error C2440: 'initializing' : cannot convert from 'const BaseClass *' to 'BaseClass *'
The error message is correct, and does not imply anything is "wrong" with Loki's SmartPtr class. The error message means your code is trying to use SmartPtr to remove const safety.
I hope that answers your question. If you have other questions, please let me know. If you are doing something else, and my reply does not address your question, feel free to clarify the problem further.
Log in to post a comment.