为什么这不能编译?
Why doesn't this compile
#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)
我使用命令行i686-apple-darwin10-gcc-4.2.1在MAC OS X 10.6.7机器上编译代码。
第66行应该是这样的:
KAutoPtr() : AutoPtr<C>()
对于其他构造函数调用也是如此。
您已经编写了KAutoPtr
模板的主体,就好像KAutoPtr<C>
是从AutoPtr
派生的一样。但事实并非如此;没有AutoPtr
型;AutoPtr
是模板,KAutoPtr<C>
来源于AutoPtr<C>
相关文章:
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么我的 EnumWindowProc 不能用 C 语言编译?
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 为什么通过指针编译时不能分配 const 初始化
- std::variant<>::get() 不能使用 Apple LLVM 10.0 编译
- 为什么使用 std::vector 的代码不能编译,但使用 std::unique_ptr 如果没有 noexcept
- 我不能用C++编译Xcode库
- 返回实例变量的c++方法可以访问变量中的数据,但不能更改它,但在编译时不会生成错误
- 为什么引用不能与编译时函数一起使用?
- 为什么我不能编译这个在Cygwin的Visual Studio中编写的C++文件?
- 为什么一个简单的"Hello World"风格的程序不能用Turbo C++编译?
- 为什么我不能编译这个简单的线程测试?
- C++程序使用 mingw 在 Linux 上交叉编译在 MSy2 中工作,但不能直接在 Windows 中工作
- 此模板函数在哪里生成?可以通过g++编译,但不能在Visual Studio中编译
- 当 pkg-config 不能解决 opencv 'undefined reference'编译问题时,如何解决它?
- 没有返回类型的静态函数可以通过Windows上的编译,但不能传递Linux上的编译
- 警告:不能解析.gnu_debugdata部分;LZMA支持在编译时被禁用
- 为什么 --string::end() 可以编译,而 --string.size() 不能编译?
- lower_bound()函数不能在调试模式下编译
- QT-不能使用外部库进行交叉编译