【发布时间】:2018-01-21 21:52:09
【问题描述】:
有一个自定义的 std::list 类助手:
#ifndef __WLIST_H
#define __WLIST_H
#include <list>
using namespace std;
template <class T >
class WList : public std::list<T>
{
public:
void wAdd();
void wRemove();
bool wContains();
void wGet();
void wClear();
int wSize();
};
#endif /*__WLIST_H*/
如何声明自定义add新项目?,在类中声明:
#include "WList.h"
template<class T>
void WList<T>::wAdd(/*???*/)
{
this->push_back(/*???*/);
}
如何在参数中设置对象类型?
【问题讨论】:
-
你不能直接将
T类型的类传递给wAdd(void WList<T>::wAdd(T object_to_add)),然后像this->push_back(object_to_add)一样添加它吗? -
如果您不知道如何声明自定义添加新项目?的答案,您需要了解a good book的语言基础知识。另外,不要从
std::list派生。标准禁止这样做。 -
@apalomer 不起作用,编译器说错误:
WList<Rectangle>::wAdd(Rectangle) is not defined -
@RSahu 一本西班牙语的好书?
-
西班牙语?这是The Definitive C++ Book Guide and List 的链接。