1
#ifndef C_H
#define C_H
#include <memory>
class C
{
public:
    C(){};
    ~C() {};
};
typedef auto_ptr<C> CPtr;


#endif

The above codes seem fine for me, but when I compile them with VC10, I got the following errors: "error C2143: syntax error : missing ';' before '<'". Any ideas about it will be appreciated.

3
  • 1
    Worth mentioning that the C++ 11 standard states that: auto_ptr has been deprecated and that unique_ptr provides a better solution.
    – hmjd
    Jul 5, 2012 at 15:45
  • Welcome to Stack Overflow! We have a mechanism for saying "Problem solved, this was the solution: ...", which is to click the green check-mark next to the correct (and in this case only) answer. There might be a time delay before you are allowed to do this, but we prefer this to editing your question to add the same information. :) Jul 5, 2012 at 15:54
  • Now I am using STLPort, and it seems that this library does not support unique_ptr yet.
    – feelfree
    Jul 5, 2012 at 15:55

1 Answer 1

6

#include <memory> gives you auto_ptr in the std-namespace, so you could make this compile by replacing your typedef with:

typedef std::auto_ptr<C> CPtr;

Alternatively, you could introduce auto_ptr into the current namespace with a using statement, though you should really not do this in a header. To do this you would need to add a statement like using std::auto_ptr; or using namespace std;.

2
  • @feelfree, you should accept this answer rather than updating the question with the solution.
    – hmjd
    Jul 5, 2012 at 15:52
  • Ok, I will do that as you suggested.
    – feelfree
    Jul 5, 2012 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.