auto_ptr fail
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <memory>
#include <iostream>
class Test
{
public:
Test():m_value(0) { std::cout << "Test::Test\n"; }
~Test() { std::cout << "Test::~Test destructor\n"; }
int m_value;
};
void doSomethig(std::auto_ptr<Test> myPtr) {
myPtr->m_value = 11;
}
void AutoPtrTest() {
std::auto_ptr<Test> myTest(new Test());
doSomethig(myTest);
myTest->m_value = 10; // ??
}
int main()
{
AutoPtrTest();
}
Enter to Rename, Shift+Enter to Preview