我有一个模板和指针问题(我认为)。下面是我的代码的一部分:C++模板和指针
/* ItemCollection.h */
#ifndef ITEMCOLLECTION_H
#define ITEMCOLLECTION_H
#include <cstddef>
using namespace std;
template <class T> class ItemCollection
{
public:
// constructor
//destructor
void insertItem(const T);
private:
struct Item
{
T price;
Item* left;
Item* right;
};
Item* root;
Item* insert(T, Item*);
};
#endif
而且具有功能确定指标的文件:
/* ItemCollectionTemp.h-member functions defintion */
#include <iostream>
#include <cstddef>
#include "ItemCollection.h"
template <class T>
Item* ItemCollection <T>::insert(T p, Item* ptr)
{
// function body
}
以下是这是由下面这行代码生成的错误:
Item* ItemCollection <T>::insert(T p, Item* ptr)
错误:
错误C2143:语法错误:缺少';'之前'*'
错误C4430:缺少类型说明符 - int假定。注意:C++不支持默认int
错误C2065: '类型':未声明的标识符
错误C2065:前缺少 ')': '类型':未声明的标识符
错误C2146:语法错误标识符'p'
错误C4430:缺少类型说明符 - 假定为int。注意:C++不支持default-int
错误C2470:'ItemCollection :: insert':看起来像一个函数定义,但没有参数列表;跳过表观体
错误C2072: 'ItemCollection ::插入':语法错误:: ')'
任何帮助非常感谢函数
错误C2059的初始化。
@Kary:既然你要求解释阿列克谢的答案,记住你不应该接受一个答案,除非你真的对此感到满意。如果你想要更多的细节,那就说,不要接受它。或者接受另一个答案,它提供了你想要的细节。 – jalf 2010-04-13 19:04:40