shared_ptr and -> operator
All, I'm replacing some standard C++ pointers with shared_ptrs. I've run into a small problem using shared_ptr with a pointer to member. With a really simple class: class TestObject{ public: TestObject():value_(-5.4){} ~TestObject(); double value_; }; Trying this: double TestObject::*dptr = 0; shared_ptr<TestObject> testPtr = shared_ptr<TestObject>(new TestObject()); testPtr->*dptr = 5.7456; On VS2005, I get an error on the ->*: error C2296: '->*' : illegal, left operand has type 'boost::shared_ptr<T>' This line is fine: (*testPtr).*dptr = 5.7456; Can anyone tell me why the compiler isn't converting boost::shared_ptr<TestObject> to a TestObject* through shared_ptr::operator-> ? I can live with dereferencing the testPtr, but I'd like to understand what's going on. Damien
We are moving a windows JNI library to the Linux work.... Yahoo.. We used the boost library for some of our work and we have it compiling under Eclipse C/C++ (g++) without errors. The Problem is....When I run ldd -r AliveJNI.so... I get a bunch of "Undefined Symbols" for the boost library. I want them to be linked in statically so I only have to ship one file with my product. What am I doing wrong. The linker isn't complaining, but when I call it or use ldd I get undefined symbols. <OUTPUT FROM LDD BELOW> [root@localhost Debug]# ldd -r AliveJNI.so libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000002a956d5000) libm.so.6 => /lib64/tls/libm.so.6 (0x0000002a958c6000) libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000002a95a4c000) libc.so.6 => /lib64/tls/libc.so.6 (0x0000002a95b57000) /lib64/ld-linux-x86-64.so.2 (0x000000552aaaa000) undefined symbol: _ZTIN5boost10lock_errorE (./AliveJNI.so) undefined symbol: _ZN5boost10lock_errorD1Ev (./AliveJNI.so) undefined symbol: _ZN5boost5mutex7do_lockEv (./AliveJNI.so) undefined symbol: _ZN5boost10filesystem6detail10status_apiERKSsRi (./AliveJNI.so) undefined symbol: aio_read (./AliveJNI.so) undefined symbol: _ZN5boost10filesystem6detail20create_directory_apiERKSs (./AliveJNI.so) undefined symbol: aio_error (./AliveJNI.so) undefined symbol: _ZN5boost10filesystem12wpath_traits11to_externalERKNS0_10basic_pathISbIw St11char_traitsIwESaIwEES1_EERKS6_ (./AliveJNI.so) undefined symbol: crcInit (./AliveJNI.so) undefined symbol: _ZN5boost5mutexC1Ev (./AliveJNI.so) undefined symbol: crcFast (./AliveJNI.so) undefined symbol: _ZN5boost10lock_errorC1Ev (./AliveJNI.so) undefined symbol: aio_return (./AliveJNI.so) undefined symbol: aio_write (./AliveJNI.so) undefined symbol: _ZN5boost5mutex9do_unlockEv (./AliveJNI.so) undefined symbol: _ZN5boost5mutexD1Ev (./AliveJNI.so) [root@localhost Debug]#
On Dec 6, 2007 2:22 PM, Damien Hocking
[snip]
testPtr->*dptr = 5.7456;
On VS2005, I get an error on the ->*:
error C2296: '->*' : illegal, left operand has type 'boost::shared_ptr<T>'
This line is fine:
(*testPtr).*dptr = 5.7456;
Can anyone tell me why the compiler isn't converting boost::shared_ptr<TestObject> to a TestObject* through shared_ptr::operator-> ?
shared_ptr overloads the -> operator but not the ->* operator (they are two separate operators). In an expression like testPtr->*dptr = 5.7456; it's looking for the ->* operator, not ->. HTH, Stjepan
participants (3)
-
Bill Nortman
-
Damien Hocking
-
Stjepan Rajko