gpt4 book ai didi

c++ - 我无法使用模板编译此代码

转载 作者:行者123 更新时间:2023-11-30 02:35:59 24 4
gpt4 key购买 nike

<分区>

我正在尝试编译用 C++ 编写的代码。

我在 fifo_list.h 中有这段代码

template <class T>
class FIFO_LIST
{
public:
class list_type {
public:
T data;
list_type *next;
void *operator new(size_t num_bytes)
{
block_pool mem_pool;

void *mem_addr = mem_pool.pool_alloc( num_bytes );
return mem_addr;
} // new
}; // class list_type
private:

list_type *list;

public:
/** define a handle type to abstract the list_type type */
typedef list_type *handle
handle first(void)
{
return list;
} // first

}

和这个头文件 queue.h:

#include "fifo_list.h"
template <class T>
class queue : protected FIFO_LIST<queueElem<T> *>
{
public:
queueElem<T> *queueStart()
{
handle h = first();
queueElem<T> *elem = get_item( h );
return elem;
}
}

当我尝试编译时出现以下错误消息:

include/queue.h: In member function ‘queueElem<T>* queue<T>::queueStart()’:
include/queue.h:100: error: ‘handle’ was not declared in this scope
include/queue.h:100: error: expected ‘;’ before ‘h’
include/queue.h:101: error: ‘h’ was not declared in this scope

我哪里错了?

@Piotr Skotnicki, @Barry 我已经这样修改了代码

queueElem<T> *queueStart()
{
//handle h = first();
typename FIFO_LIST<queueElem<T> *>::handle h = first();
queueElem<T> *elem = get_item( h );
return elem;
} // queueStart

现在我有这个错误:

include/queue.h:101: error: there are no arguments to ‘first’ that  depend on a template parameter, so a declaration of ‘first’ must be available

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com