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


#endif

上面的代码对我来说似乎很好,但是当我用 VC10 编译它们时,我得到了以下错误:“错误 C2143:语法错误:缺少';' 在'<'”之前。任何关于它的想法将不胜感激。

4

1 回答 1

6

#include <memory>auto_ptrstd-namespace中为您提供,因此您可以通过将您的替换typedef为:

typedef std::auto_ptr<C> CPtr;

或者,您可以auto_ptr使用语句将其引入当前命名空间using,尽管您实际上不应该在标题中执行此操作。为此,您需要添加类似using std::auto_ptr;or的语句using namespace std;

于 2012-07-05T15:43:32.503 回答