【问题标题】:Why doesn't this compile [closed]为什么这不编译[关闭]
【发布时间】:2011-07-29 01:13:37
【问题描述】:
#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& ptr) : AutoPtr(ptr)

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

【问题讨论】:

  • 也许语法不正确?
  • 叹息。 从小处着手,逐步建立,每一步都进行测试。永远不要添加不起作用的代码。
  • @Beta:公平地说,那里几乎没有任何代码。
  • @OliverCharlesworth 总共有 14 个类,即 14 个需要链接的头文件和 cpp 文件,这对我来说是很多代码,至少大约 29 个文件........

标签: c++ gcc compiler-errors poco-libraries


【解决方案1】:

第 66 行应该是这样的:

KAutoPtr() : AutoPtr<C>()

对于其他构造函数调用也是如此。

【讨论】:

  • 谢谢!此代码已签入并为我团队中使用 Microsoft Visual Studio 2005 的某个人工作,但在 MAC 端破坏了我的编译。
【解决方案2】:

您编写了KAutoPtr 模板的主体,就好像KAutoPtr&lt;C&gt; 派生自AutoPtr。但事实并非如此;没有类型AutoPtrAutoPtr 是一个模板,KAutoPtr&lt;C&gt; 派生自 AutoPtr&lt;C&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-01
    • 2014-10-09
    • 2012-10-24
    • 1970-01-01
    • 2012-09-09
    • 1970-01-01
    相关资源
    最近更新 更多