How*_*Gee 3 c++ templates header-files visual-studio-2010
所以当我编译程序时,我收到一个奇怪的错误:
Error 1 error C2143: syntax error : missing ';' before ''template<''
我做的每件事都很标准; 没什么特别的:
#ifndef HEAP_H
#define HEAP_H
//**************************************************************************
template<typename TYPE>
class Heap
{
private:
TYPE* heapData;
int currSize;
int capacity;
void _siftUp(int);
void _siftDown(int);
int _leftChildOf(int) const;
int _parentOf(int) const;
public:
Heap(int c = 100);
~Heap();
bool viewMax(TYPE&) const;
int getCapacity() const;
int getCurrSize() const;
bool insert(const TYPE&);
bool remove(TYPE&);
};
Run Code Online (Sandbox Code Playgroud)
不太确定是什么问题.我尝试关闭并重新打开我的程序 - 没有运气.使用Visual Studio 2010
Dre*_*ann 11
这个错误可能有点误导.
之前;
发生的事情并不一定重要. template<
在;
实际预期后,无论没发生之前template<
.
此示例显示了这可能发生的方式.
文件 header.h
class MyClass
{
}
Run Code Online (Sandbox Code Playgroud)
文件 heap.h
#ifndef HEAP_H
#define HEAP_H
//**************************************************************************
template<typename TYPE>
class Heap
{
};
#endif
Run Code Online (Sandbox Code Playgroud)
文件 main.cpp
#include "header.h"
#include "heap.h"
int main()
{
}
Run Code Online (Sandbox Code Playgroud)
编辑:
此编译器错误导致您返回错误文件的原因是在编译之前,预处理器将处理main.cpp
为此单个字符流.
class MyClass
{
}
//**************************************************************************
template<typename TYPE>
class Heap
{
};
int main()
{
}
Run Code Online (Sandbox Code Playgroud)