I'm getting a strange error when I'm compiling my program:
Error 1 error C2143: syntax error : missing ';' before ''template<''
I'm doing everything pretty standard; nothing out of the ordinary:
#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&);
};
Not quite sure what's wrong. I tried closing and reopening my program - no luck. Using Visual Studio 2010
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()
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With