ERROR C2143: Syntax error: missing ';' before '<' C++ -
i having trouble in c++ code have make binary heap. works fine long had "main" function inside of "myheap.h" file professor wants run in separate test file. reason code doesn't want run whenever try put main function outside of "myheap.h" file. when runs following error:
error c2143: syntax error: missing';' before '<' i looked @ code , says there error can't see anything.
// myheap.h #ifndef _myheap_h #define _myheap_h #include <vector> #include <iterator> #include <iostream> class heap { public: heap(); ~heap(); void insert(int element); int deletemax(); void print(); int size() { return heap.size(); } private: int left(int parent); int right(int parent); int parent(int child); void heapifyup(int index); void heapifydown(int index); private: vector<int> heap; }; #endif // _myheap_h so said whenever have the int main function right after private class, work fine. when implement test file this:
#include "myheap.h" #include <vector> #include <iostream> int main() { // create heap heap* myheap = new heap(); myheap->insert(25); myheap->print(); myheap->insert(75); myheap->print(); myheap->insert(100); myheap->print(); myheap->deletemax(); myheap->print(); myheap->insert(500); myheap->print(); return 0; } it keeps popping errors, ideas on go fixing problem code can run test file?
use std::vector instead of vector.
the compiler complaining doesn't know vector.
since lives in std namespace, safest solution prefix std.
Comments
Post a Comment