Missing ';' before 'template<'

醉酒当歌 提交于 2019-12-01 21:43:47

That error can be a little misleading.

It's not necessarily important that a ; occur before template<.

The ; was actually expected after whatever did occur before template<.

This example shows how this could happen.

File header.h

class MyClass
{

}

File heap.h

#ifndef HEAP_H
#define HEAP_H
//**************************************************************************
template<typename TYPE>
class Heap
{
};

#endif

File main.cpp

#include "header.h"
#include "heap.h"

int main()
{
}

Edit:

The reason this compiler error led you to the wrong file is that before compilation, the preprocessor will process main.cpp into this single stream of characters.

class MyClass
{

}

//**************************************************************************
template<typename TYPE>
class Heap
{
};

int main()
{
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!