为什么这个不能编译

发布于 2024-11-27 06:47:58 字数 2598 浏览 0 评论 0原文

#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

line 66 is KAutoPtr(const AutoPtr& ptr) : AutoPtr(ptr)

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

#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
    };

I get the following errors:

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

line 66 is KAutoPtr(const AutoPtr& ptr) : AutoPtr(ptr)

I am using the command line i686-apple-darwin10-gcc-4.2.1 to compile the code on MAC OS X 10.6.7 machine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅忆流年 2024-12-04 06:47:58

第 66 行应该是这样的:

KAutoPtr() : AutoPtr<C>()

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

Line 66 should be this:

KAutoPtr() : AutoPtr<C>()

And similarly for the other constructor calls.

傲娇萝莉攻 2024-12-04 06:47:58

您已经编写了 KAutoPtr 模板的正文,就像从 AutoPtr 派生的 KAutoPtr 一样。但事实并非如此;没有类型AutoPtrAutoPtr 是一个模板,KAutoPtr 派生自 AutoPtr

You have written the body of the KAutoPtr template as if KAutoPtr<C> derived from AutoPtr. But it does not; there is no type AutoPtr; AutoPtr is a template, and KAutoPtr<C> derives from AutoPtr<C>.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文