C++ 基类中的模板类,在dervied类中包括/使用

C++ 基类中的模板类,在dervied类中包括/使用,c++,include,C++,Include,我有一个名为item的模板类。 我有另一个类,它具有项的数组s-class哈希表。 我有第三个类,它来自hashTable-HSubject。 我对我必须添加到每个类中的使用/包含感到困惑。 我尝试了许多选项,但它产生了运行时错误 代码附于此处: *item.h* #pragma once #include "stdafx.h" #include <iostream> #include <list> #include <string> #

我有一个名为item的模板类。 我有另一个类,它具有项的数组s-class哈希表。 我有第三个类,它来自hashTable-HSubject。 我对我必须添加到每个类中的使用/包含感到困惑。 我尝试了许多选项,但它产生了运行时错误

代码附于此处:

*item.h*

#pragma once
#include "stdafx.h"
#include <iostream>
#include <list>
#include <string>
#include <vector>
using namespace std;

enum state { empty, full, deleted };

template <class T, class K>
class item
{
// propeties and functions here
};
*item.h*
#布拉格语一次
#包括“stdafx.h”
#包括
#包括
#包括
#包括
使用名称空间std;
枚举状态{空、满、已删除};
模板
类项目
{
//这里的性质和函数
};
*hashTable.h*
#布拉格语一次
#包括
#包括
#包括
#包括
#包括“项目h”
使用名称空间std;
//尝试添加此项,但似乎不起作用
//模板
//类别项目;
模板
类哈希表
{
公众:
向量hashT;
哈希表();
//这里的性质和函数
};
*hashTable.cpp*
#布拉格语一次
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括
#包括“hashTable.h”
使用名称空间std;
模板
hashTable::hashTable()
{}
//函数写在这里
*HSubject.h*
#布拉格语一次
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括
类别项目;
使用名称空间std;
H类主体:
公共哈希表
{
公众:
HSubject();
//这里的性质和函数
};
*HSubject.cpp*
#布拉格语一次
#包括“stdafx.h”
#包括
#包括
#包括
#包括
#包括
#包括“hashTable.h”
#包括“HSubject.h”
#包括“项目h”
使用名称空间std;
HSubject::HSubject():哈希表()
{
}
//函数写在这里

任何帮助都将是巨大的。谢谢

您几乎肯定希望在其头文件中实现类模板的所有成员函数。特别是,请参阅,您几乎肯定希望在其头文件中实现类模板的所有成员函数。特别是,请参阅
*hashTable.h*

#pragma once
#include <iostream>
#include <list>
#include <string>
#include <vector>
#include "item.h"

using namespace std;

// tried adding this but didn't seem to work
//template <class T, class K>
//class item<T, K>;

template <class T, class K>
class hashTable
{
public: 
    vector<item<T, K>> hashT;
    hashTable();
    // propeties and functions here
};
*hashTable.cpp*

#pragma once
#include "stdafx.h"
#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <memory>
#include "hashTable.h"
using namespace std;

template<class T, class K>
hashTable<T, K>::hashTable() 
{}
// functions are written here
*HSubject.h*

#pragma once
#include "stdafx.h"
#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <memory>

class item<list<string>, string>;

using namespace std;
class HSubject :
    public hashTable<list<string>, string>
{
public:
    HSubject();
    // propeties and functions here
};
*HSubject.cpp*

#pragma once
#include "stdafx.h"
#include <iostream>
#include <list>
#include <string>
#include <vector>
#include <memory>
#include "hashTable.h"
#include "HSubject.h"
#include "item.h"
using namespace std;

HSubject::HSubject() : hashTable()
{
}
// functions are written here