Linked Questions

467 votes
17 answers
261k views

I understand the syntax and general semantics of pointers versus references, but how should I decide when it is more-or-less appropriate to use references or pointers in an API? Naturally some ...
connec's user avatar
  • 7,481
113 votes
5 answers
111k views

If I declare an object wrapped in a shared pointer: std::shared_ptr<myClass> myClassObject(new myClass()); then I wanted to pass it as an argument to a method: DoSomething(myClassObject); //...
Steve H's user avatar
  • 5,514
66 votes
5 answers
23k views

I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function arguments. Consider the following: class Dataset {...} void f( shared_ptr< Dataset ...
Artem Sokolov's user avatar
26 votes
6 answers
17k views

I recall reading somewhere that using references to smart pointers can cause memory corruption. Is this simply because of using the reference of the smart pointer after its been destroyed? Or does ...
Superpolock's user avatar
  • 3,643
12 votes
4 answers
16k views

I have a program that uses boost::shared_ptrs and, in particular, relies on the accuracy of the use_count to perform optimizations. For instance, imagine an addition operation with two argument ...
AndyJost's user avatar
  • 1,133
7 votes
2 answers
11k views

I'm currently wrapping a C++ class with C++/CLI for .NET interoperability following the standard process of holding a native pointer in a managed class. In one instance, I have a native class that has ...
Seth's user avatar
  • 8,373
10 votes
4 answers
9k views

there are already a couple of questions regarding this topic, but I am still not sure what to do: Our codebase uses shared_ptr at many places. I have to admit that we did not define ownership clearly ...
Philipp's user avatar
  • 11.7k
9 votes
3 answers
9k views

Is it possible, and if so, how can I create a signal/slot in Qt that is a const reference to a shared_ptr? I want a signal that looks like this: void signal( shared_ptr<SomeClass> const & )...
edA-qa mort-ora-y's user avatar
7 votes
4 answers
3k views

I want to pass an object by smart-pointer reference to a function. The function may change the value of the referenced object, but may not change the reference itself. There are two obvious ways to ...
user avatar
1 vote
3 answers
190 views

Let's consider this class: class X { std::map<uint32_t, uint32_t> _map; public: X() { /* Populate the map */ } std::map<uint32_t, uint32_t> getTheMap() { return _map; } }; ...
Vincenzo Pii's user avatar
  • 20.1k
0 votes
0 answers
193 views

Can an excessive use of smart pointers (especially shared_ptr) cause an increase in kernel calls? I am trying to optimize and simplify a real-time (QNX) codebase. One focus besides memory and realtime ...
Khashayar's user avatar
  • 488