Jump to content
  • Advertisement
Sign in to follow this  
Rohithzhere

LEARNING AUTO_PTR

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by phresnel
In 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!