197 questions
1
vote
1
answer
109
views
Type of a global object dependent on boolean flag (determined at runtime)
I want to do something like the following
if (flag) {
type1_t object = .....
} else {
type2_t object = .....
}
// do the same thing with object
type1_t and type2_t are custom classes. The problem ...
0
votes
1
answer
108
views
In smart_ptr constructor, why pass by value and not pass by const ref?
I've been reading the section on smart pointers in Scott Meyer's "Effective C++" and "More Effective C++." In it, there is an implementation of auto_ptr for which the constructor ...
2
votes
1
answer
3k
views
How do I re-enable C++17 removed features in clang?
I have some 3rdparty libraries that are built as part of a large project. Some libraries require C++17, others require features that are removed in C++17 (std::auto_ptr, std::fun_ptr).
For this ...
2
votes
2
answers
122
views
Example of C++ std::vector<std::auto_ptr<T>> that compiles but fails
What would be a simple C++ program where a std::vector<std::auto_ptr<T>> compiles but fails to execute correctly, whereas the same program with std::vector<std::unique_ptr<T>> ...
2
votes
1
answer
214
views
c++ auto_ptr destroyed when passed into a function
Suppose that we have
void UsePointer (auto_ptr <CSomeClass> spObj)
{
spObj->DoSomething();
}
and we have a main function:
int main()
{
auto_ptr <CSomeClass> spObject (new ...
2
votes
2
answers
469
views
Using auto_ptr<std::ofstream> object
I need to store my error and log messages to the file. This is the code sample:
#include <fstream>
#include <iostream>
#include <memory>
int main()
{
std::auto_ptr<std::...
1
vote
3
answers
360
views
Why unique_ptr works but auto_ptr doesn’t with STL
I have referred to lot of StackOverflow links on these questions where the reason for auto_ptr not working well with STL is
std::auto_ptr<> does not fulfill the requirements of being copy-...
0
votes
0
answers
77
views
storing std::auto_ptr in a container [duplicate]
It is said that we should always use std::unique_ptr instead of std::auto_ptr and it is said that we were not able to store a auto_ptr in a container But consider this example:
int main(int argc, ...
2
votes
2
answers
2k
views
Why is using a reference or unique pointer member of a class a bad thing?
In the book "C++ Coding Standards. 101 Rules, Guidelines, and Best Practices" by Herb Sutter and Andrei Alexandrescu in Rule 52, the final quote is:
"In rare cases, classes that have members of ...
0
votes
0
answers
85
views
smart pointer with unexpected behavior
As i was going through smart pointers, I ran through the following code.
Works as expected.
#include <iostream>
#include <memory>
using namespace std;
class Double
{
public:
Double(...
0
votes
1
answer
472
views
unique_ptr/auto_ptr look alike with custom deleter for c++98
auto_ptr doesn't support custom deleter and tr1 shared_ptr is not a good option for me.
Are there any good options before c11 for unique_ptr/ auto_ptr look alike with custom deleter?
1
vote
1
answer
2k
views
Resurrecting std::auto_ptr in GCC when compiling with -std=c++17
Is there a macro or compiler flag that would let me keep using auto_ptr in GCC 7/8 with -std=c++17? I have easily found the corresponding macro for clang and MSVC, but my Google-fu is not good enough ...
0
votes
0
answers
104
views
initializing functions as auto_ptr with class reference
I'm trying to understand the flow of a code and I came across this code snippet in the header file
typedef std::auto_ptr<Client> auto_ptr_t;
static Client::auto_ptr_t open(const std::string&...
0
votes
1
answer
320
views
Alternative library/template class for the deprecated auto_ptr in C++17
Have shared project library that has to be compiled with various compilers C++17 C++03 etc. So just using the better unique_ptr or the less than perfect auto_ptr as appropriate is not ideal if the ...
0
votes
0
answers
72
views
Returning auto_ptr has different results on diferent gcc versions
I have the following test code that I'm trying to run on QNX 6.5.0SP1 using gcc 4.4.2:
// auto_ptr::operator= example
#include <iostream>
#include <cstdio>
#include <memory>
std::...