File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed
Common/ReturnObjectFromFunction Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -57,26 +57,28 @@ main()
57
57
std::cout << smartPointer->GetLargestPossibleRegion () << std::endl;
58
58
}
59
59
60
+ // Common failure modes
60
61
{
61
- ImageType * pointer = ReturnPointer ();
62
62
// This crashes the program because the smart pointer created in the function goes out of scope and gets deleted
63
63
// because it is returned as a normal pointer.
64
+
65
+ // ImageType * pointer = ReturnPointer();
64
66
// std::cout << pointer->GetLargestPossibleRegion() << std::endl;
65
- pointer = nullptr ; // Here to silence warning
66
67
}
67
68
68
69
{
69
- ImageType * pointer = ReturnSmartPointer ();
70
70
// This crashes the program because though the function returned a ::Pointer, it was not stored
71
71
// anywhere so the reference count was not increased, so it got deleted.
72
+
73
+ // ImageType * pointer = ReturnSmartPointer();
72
74
// std::cout << pointer->GetLargestPossibleRegion() << std::endl;
73
- pointer = nullptr ; // Here to silence warning
74
75
}
75
76
76
77
{
77
78
// I thought this might also work, but it does not (crash).
78
79
// My reasoning was that even though you don't return a smart pointer, you assign the object to a smart
79
80
// pointer at return time, so it still has a reference count of 1.
81
+
80
82
// ImageType::Pointer smartPointer = ReturnPointer(); // this line causes a 'glibc error'
81
83
// std::cout << smartPointer->GetLargestPossibleRegion() << std::endl;
82
84
}
Original file line number Diff line number Diff line change @@ -75,8 +75,8 @@ main(int, char *[])
75
75
76
76
while (cellDataIterator != end)
77
77
{
78
- PixelType cellValue = cellDataIterator.Value ();
79
- // std::cout << cellValue << std::endl; //same values as before
78
+ const auto cellValue = cellDataIterator.Value ();
79
+ std::cout << cellValue << std::endl; // same values as before
80
80
++cellDataIterator;
81
81
}
82
82
You can’t perform that action at this time.
0 commit comments