为什么不编译

时间:2011-07-29 01:13:37

标签: c++ gcc compiler-errors

#include "base.h"
#include <Poco/SharedPtr.h>
#include <Poco/AutoPtr.h>
#include <vector>

using Poco::SharedPtr;
using Poco::AutoPtr;


namespace kroll
{
    class Value;
    class KObject;
    class KMethod;
    class KList;

    class StaticBoundObject;
    class StaticBoundMethod;
    class StaticBoundList;

    class GlobalObject;
    class ScopeMethodDelegate;
    class Bytes;
    class VoidPtr;
    class ValueReleasePolicy;
    class Logger;
    class ArgList;

    template <class C>
    class KAutoPtr : public AutoPtr<C>
    {
    public:
        KAutoPtr() : AutoPtr()
        {}

        KAutoPtr(C* ptr) : AutoPtr(ptr)
        {}

        KAutoPtr(C* ptr, bool shared) : AutoPtr(ptr, shared)
        {}

        KAutoPtr(const AutoPtr& ptr) : AutoPtr(ptr)
        {}

        /*KAutoPtr& operator = (const AutoPtr& ptr)
        {
            return assign(ptr);
        }*/

#ifdef DEBUG
        //This is used in debug builds as a workaround to release all memory
        //before VS debugger incorrectly dumps it as memory leak.
        KObject* release()
        {
            KObject* t = _ptr;
            _ptr = 0;
            return t;
        }
#endif
    };

我收到以下错误:

kroll/libkroll/kroll.h:66: error: expected ',' or '...' before '&' token
kroll/libkroll/kroll.h:66: error: ISO C++ forbids declaration of 'AutoPtr' with no type
kroll/libkroll/kroll.h: In constructor 'kroll::KAutoPtr<C>::KAutoPtr()':
kroll/libkroll/kroll.h:57: error: class 'kroll::KAutoPtr<C>' does not have any field named 'AutoPtr'
kroll/libkroll/kroll.h: In constructor 'kroll::KAutoPtr<C>::KAutoPtr(C*)':
kroll/libkroll/kroll.h:60: error: class 'kroll::KAutoPtr<C>' does not have any field named 'AutoPtr'
kroll/libkroll/kroll.h: In constructor 'kroll::KAutoPtr<C>::KAutoPtr(C*, bool)':
kroll/libkroll/kroll.h:63: error: class 'kroll::KAutoPtr<C>' does not have any field named 'AutoPtr'
kroll/libkroll/kroll.h: In constructor 'kroll::KAutoPtr<C>::KAutoPtr(int)':
kroll/libkroll/kroll.h:66: error: class 'kroll::KAutoPtr<C>' does not have any field named 'AutoPtr'
kroll/libkroll/kroll.h:66: error: 'ptr' was not declared in this scope
kroll/libkroll/kroll.h: In member function 'kroll::KObject* kroll::KAutoPtr<C>::release()':
kroll/libkroll/kroll.h:79: error: '_ptr' was not declared in this scope

第66行是KAutoPtr(const AutoPtr&amp; ptr):AutoPtr(ptr)

我使用命令行i686-apple-darwin10-gcc-4.2.1在MAC OS X 10.6.7机器上编译代码。

2 个答案:

答案 0 :(得分:8)

第66行应为:

KAutoPtr() : AutoPtr<C>()

类似于其他构造函数调用。

答案 1 :(得分:0)

您已编写KAutoPtr模板的正文,好像KAutoPtr<C>来自AutoPtr。但事实并非如此;没有类型AutoPtr; AutoPtr是一个模板,KAutoPtr<C>来自AutoPtr<C>