shared-ptr

Get Eclipse CDT + boost::shared_ptr<T> to work with syntax completion?

泪湿孤枕 提交于 2020-01-01 16:26:33
问题 How to get Eclipse CDT to treat shared_ptr as T * for syntax completion? I'm using windows in this instance. I have 1.39 in the "Program Files" folder. I am about to try 1.37. I am using the Galileo release of Eclipse. Also, I am only editing and browsing the source in Eclipse and building in VC++ Express. (but that is another story) 回答1: What version of boost are you using? According to this thread: Turns out there is something about Boost 1.39 that the CDT indexer does not like. If I allow

How can I take a single element out of a boost library (e.g. shared_pointer)?

我是研究僧i 提交于 2020-01-01 09:34:07
问题 I've been playing around with some Boost components, and the only one I see a direct need for in the project I'm working on is boost::shared_ptr . Would it be difficult to just include the required files for shared_ptr , or at least just include files for the Boost smart_ptr directory in my project? They seem to have some external dependencies on other parts of Boost - but I figure there's an easy way to just use certain components of the Boost library and I'm missing it. If you can tell me

C++ passing a derived class shared_ptr to a templated function

人走茶凉 提交于 2019-12-31 03:20:51
问题 First something that should work, then something that doesn't. Why doesn't it is the question. I declare two classes: class Base { ... }; class Derived : public Base { ... }; I then have the following function elsewhere: void foo(shared_ptr<Base> base); The following code should work right? share_ptr<Derived> derived; foo(derived); Now, forget the above, I declare three classes: class Foo { ... }; template <typename TYPE> class Base { ... }; class Derived : public Base<Foo> { ... }; Elsewhere

implicit instantiation of undefined template: Boost Bug or Clang Bug?

∥☆過路亽.° 提交于 2019-12-31 02:55:35
问题 I was trying to compile some code that uses Boost (1.49), with Clang(& libc++) from trunk. The problematic code boils down to the following: #include <memory> #include <boost/signals2.hpp> int main() { std::shared_ptr<int> s; } When compiled with Clang, the following message is emmited: $ clang++ -I/home/alexander/usr/local/include --stdlib=libc++ -std=c++0x signals2-bug.cpp -o signals2-bug signals2-bug.cpp:6:26: error: implicit instantiation of undefined template 'std::shared_ptr<int>' std:

C++ volatile required when spinning on boost::shared_ptr operator bool()? [duplicate]

放肆的年华 提交于 2019-12-30 12:23:59
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: When to use volatile with multi threading? I have two threads referencing the same boost::shared_ptr : boost::shared_ptr<Widget> shared; On thread is spinning, waiting for the other thread to reset the boost::shared_ptr : while(shared) boost::thread::yield(); And at some point the other thread will call: shared.reset(); My question is whether or not I need to declare the shared pointer as volatile to prevent the

C++ volatile required when spinning on boost::shared_ptr operator bool()? [duplicate]

左心房为你撑大大i 提交于 2019-12-30 12:23:11
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: When to use volatile with multi threading? I have two threads referencing the same boost::shared_ptr : boost::shared_ptr<Widget> shared; On thread is spinning, waiting for the other thread to reset the boost::shared_ptr : while(shared) boost::thread::yield(); And at some point the other thread will call: shared.reset(); My question is whether or not I need to declare the shared pointer as volatile to prevent the

std::enable_shared_from_this: is it allowed to call shared_from_this() in destructor?

可紊 提交于 2019-12-30 08:08:48
问题 #include <memory> #include <iostream> struct A : public std::enable_shared_from_this<A> { ~A() { auto this_ptr = shared_from_this(); // std::bad_weak_ptr exception here. std::cout << "this: " << this_ptr; } }; int main() { auto a = std::make_shared<A>(); a.reset(); return 0; } I'm getting std::bad_weak_ptr exception when calling shared_from_this() . Is it by design? Yes, it might be dangerous as this pointer can't be used after the destructor returns, but I don't see a reason why it would be

Why use one vs the other: `boost::shared_array` VS `boost::shared_ptr<std::vector>`?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-30 07:07:20
问题 So to deal with large blobs of memory either for an image or similar there are clearly lots of options. Since I'm a fan of smart pointers and RAII I'm wondering about whether it's smarter to go with : a shared_ptr to a std::vector or to go with a shared_array pointing to a dynamically allocated array. What are the conceptual, practical, and performance implications of choosing one vs the other? 回答1: It's the same as comparing std::vector vs. C array. Think about shared_array as a RAII C array

Manually incrementing and decrementing a boost::shared_ptr?

﹥>﹥吖頭↗ 提交于 2019-12-30 06:49:07
问题 Is there a way to manually increment and decrement the count of a shared_ptr in C++? The problem that I am trying to solve is as follows. I am writing a library in C++ but the interface has to be in pure C. Internally, I would like to use shared_ptr to simplify memory management while preserving the ability to pass a raw pointer through the C interface. When I pass a raw pointer through the interface, I would like to increment the reference count. The client will then be responsible to call a

Manually incrementing and decrementing a boost::shared_ptr?

我只是一个虾纸丫 提交于 2019-12-30 06:49:05
问题 Is there a way to manually increment and decrement the count of a shared_ptr in C++? The problem that I am trying to solve is as follows. I am writing a library in C++ but the interface has to be in pure C. Internally, I would like to use shared_ptr to simplify memory management while preserving the ability to pass a raw pointer through the C interface. When I pass a raw pointer through the interface, I would like to increment the reference count. The client will then be responsible to call a