# LEARNING AUTO_PTR

This topic is 3668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I am learning the use of auto_ptr. I came across a sample in wiki. But when i paste the code in my project, it is throwing up a few errors. Do i need any specific project settings for that?? Here goes the sample

include <iostream>
using namespace std;

int *i = new int;
auto_ptr<int> x(i);
auto_ptr<int> y;

y = x;

cout << x.get() << endl;
cout << y.get() << endl;


And the Errors are Error 1 error C2143: syntax error : missing ';' before '<' e:\Rohith\C++\callback\callback\FPTR.cpp 111 Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 111 Error 3 error C2143: syntax error : missing ';' before '<' 112 Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 112 Error 5 error C2086: 'int auto_ptr' : redefinition 112 Error 6 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 114 Error 7 error C2065: 'x' : undeclared identifier 114 Error 8 error C2143: syntax error : missing ';' before '<<' 116 Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 116 Error 10 error C2143: syntax error : missing ';' before '<<' 117 Error 11 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 117 Error 12 error C2086: 'int cout' : redefinition 117 The datatypes are not being recognized at all??...Pls Help Thanks and Regards, Rohith.H.N

##### Share on other sites
If that's not the actual code, then you should post the actual code (remember to use [ source ] tags). If that is the actual code, then for starters:

1. You're missing an # in front of your include.

2. In general, executable code needs to go inside a function of some sort.

3. You have no entry point (i.e. main()).

(Oh, and you might edit your thread title - using all caps is generally discouraged on forums such as these.)

##### Share on other sites
#include <memory>

##### Share on other sites
In C++0x, auto_ptr's are deprecated. See here.

Try those smart pointers, which will be part of the upcoming standard. They also have proper documentation. An introduction can also be found at Dr. Dobbs.

##### Share on other sites
Quote:
 Original post by phresnelIn C++0x, auto_ptr's are deprecated.

That's a pretty useless observation if you're not working with a C++0x compiler since the replacement, unique_ptr, requires rvalue references to implement.

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633696
• Total Posts
3013394
×