C++ c++;从头文件中引用类的实现时出现模板类错误

C++ c++;从头文件中引用类的实现时出现模板类错误,c++,visual-studio-2010,templates,C++,Visual Studio 2010,Templates,编辑:我修复后重新启动一切从头开始。我不确定是什么导致了这个问题。如果有人有任何想法,或洞察是什么导致了主要问题,我将编辑第一篇文章,并提供后续内容 所以我正在做一个家庭作业来创建一个heap类,它利用一个模板来使用数字数据和字符串。我使用的编译器是VisualStudio2010 头文件如下所示 #ifndef HEAP_H #define HEAP_H #include <iostream> #include <vector> // not needed

编辑:我修复后重新启动一切从头开始。我不确定是什么导致了这个问题。如果有人有任何想法,或洞察是什么导致了主要问题,我将编辑第一篇文章,并提供后续内容

所以我正在做一个家庭作业来创建一个heap类,它利用一个模板来使用数字数据和字符串。我使用的编译器是VisualStudio2010

头文件如下所示

#ifndef HEAP_H
#define HEAP_H

#include <iostream>
#include <vector>       // not needed if you use a static array

using std::cout;
using std::endl;
using std::vector;
template <typename type>
class Heap {
... the method headers I have to implement in the Heap.template file
};
#include "Heap.template"

#endif
\ifndef HEAP\u H
#定义堆
#包括
#包含//如果使用静态数组,则不需要
使用std::cout;
使用std::endl;
使用std::vector;
模板
类堆{
…我必须在Heap.template文件中实现的方法头
};
#包括“Heap.template”
#恩迪夫
我们应该在Heap.template文件中实现Heap的方法。然而,我无法编译而不被错误破坏。以下是讲师自己提供的第一种方法:

template <typename type>
Heap<type>::Heap(bool maxheap) {
// this default constructor supports a dynamic array. In this array, the root
// of the heap begins at index 1; the variable "dummy" is used to fill the 
// zero position of the dynamic array.  
type dummy;
  this->maxheap = maxheap;
  heap.push_back(dummy);
  size = heap.size()-1;
}
模板
Heap::Heap(bool maxheap){
//此默认构造函数支持动态数组。在此数组中,根
//堆的属性从索引1开始;变量“dummy”用于填充
//动态数组的零位置。
型假人;
这->maxheap=maxheap;
堆。推回(虚拟);
size=heap.size()-1;
}
即使我注释掉了我实现的其余方法,我仍然会看到错误

error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-     int
error C2988: unrecognizable template declaration/definition
error C2059: syntax error : '<'

错误C2143:语法错误:缺少“;”在“之前,在定义成员函数时,不应在类中包含
。这样做:

template <typename type>
Heap::Heap(bool maxheap) {
    //...
}
模板
Heap::Heap(bool maxheap){
//...
}

由于
template
语句,编译器已经知道类使用了这些模板参数。

我尝试了这个方法,但没有解决问题。我从头开始重新启动了一切,创建了一个新的空项目,重新下载了文件,错误不再存在。所以我真的不确定是什么原因造成的。还值得注意的是,在我的Heap.template中,如果我省略了成员函数中的,它实际上会给我一个错误,并且只有在遵循Heap::Function()格式时才会编译。
template <typename type>
void Heap<type>::PrintHeap()
{
for( std::vector<type>::iterator i = heap.begin(); i != heap.end(); ++i)
{
    cout << *i << ' ';
}
}
template <typename type>
Heap::Heap(bool maxheap) {
    //...
}