T
Tayfun Özdemir
Hello there,
I have a school project and I have to finish it soon.
I have to implement B+ Tree for the project.
I have TreeNode template class. That will be used to hold keys in the tree
index.
I have LeafNode template class derivered from TreeNode. That will be used to
hold keys and values in leaf.
Everything seems fine but it does not compile under MS.Net and gcc. It
compiles Dev-C++ but linker can not find Insert function and gives error.
I have checked many resources but I could not find the error. I would be
glad if you could explain me what is wrong.
Errors I get
TreeNode.h(5): error C2059: syntax error : '<' (The same line with
template)
TreeNode.h(5): error C2143: syntax error : missing '{' before '<' (The same
line with template)
TreeNode.c(3): error C2059: syntax error : '<'
main.c(9): error C2059: syntax error : 'type'
and the list goes like this.
I would be glad if you could explain me what is wrong.
////////////// TreeNode.h////////////////
////////////// TreeNode.h////////////////
////////////// TreeNode.h////////////////
#ifndef __TREE_NODE__
#define __TREE_NODE__
template <class KeyType, class ValType, int SIZE>
class TreeNode
{
public:
TreeNode() : nCount(0)
{};
virtual void Insert(KeyType Key, ValType Val, KeyType &ParentKey,
TreeNode<KeyType, ValType, SIZE> *&LeftChild,
TreeNode<KeyType, ValType, SIZE> *&RightChild);
protected:
int nCount;
KeyType e_Keys[SIZE];
TreeNode<KeyType, ValType, SIZE> *e_Childs[SIZE];
};
#endif
////////////// LeafNode.h////////////////
////////////// LeafNode.h////////////////
////////////// LeafNode.h////////////////
#include "TreeNode.h"
#ifndef __LEAF_NODE__
#define __LEAF_NODE__
template <class KeyType, class ValType, int SIZE>
class LeafNode : public TreeNode<KeyType, ValType, SIZE>
{
public:
LeafNode()
{
nCount = 0;
};
virtual void Insert(KeyType Key, ValType Val, KeyType &ParentKey,
TreeNode<KeyType, ValType, SIZE> *&LeftChild,
TreeNode<KeyType, ValType, SIZE> *&RightChild);
protected:
ValType e_Vals[SIZE];
};
#endif
////////// Main.c for testing //////////////////
////////// Main.c for testing //////////////////
////////// Main.c for testing //////////////////
int main(int argc, char *argv[])
{
int a, b, c, d;
LeafNode<int, int, 7> TestNode;
TreeNode<int, int, 7> *e, *f;
TestNode.Insert(10, 10, a, e, f);
return 0;
}
Tayfun Ozdemir
I have a school project and I have to finish it soon.
I have to implement B+ Tree for the project.
I have TreeNode template class. That will be used to hold keys in the tree
index.
I have LeafNode template class derivered from TreeNode. That will be used to
hold keys and values in leaf.
Everything seems fine but it does not compile under MS.Net and gcc. It
compiles Dev-C++ but linker can not find Insert function and gives error.
I have checked many resources but I could not find the error. I would be
glad if you could explain me what is wrong.
Errors I get
TreeNode.h(5): error C2059: syntax error : '<' (The same line with
template)
TreeNode.h(5): error C2143: syntax error : missing '{' before '<' (The same
line with template)
TreeNode.c(3): error C2059: syntax error : '<'
main.c(9): error C2059: syntax error : 'type'
and the list goes like this.
I would be glad if you could explain me what is wrong.
////////////// TreeNode.h////////////////
////////////// TreeNode.h////////////////
////////////// TreeNode.h////////////////
#ifndef __TREE_NODE__
#define __TREE_NODE__
template <class KeyType, class ValType, int SIZE>
class TreeNode
{
public:
TreeNode() : nCount(0)
{};
virtual void Insert(KeyType Key, ValType Val, KeyType &ParentKey,
TreeNode<KeyType, ValType, SIZE> *&LeftChild,
TreeNode<KeyType, ValType, SIZE> *&RightChild);
protected:
int nCount;
KeyType e_Keys[SIZE];
TreeNode<KeyType, ValType, SIZE> *e_Childs[SIZE];
};
#endif
////////////// LeafNode.h////////////////
////////////// LeafNode.h////////////////
////////////// LeafNode.h////////////////
#include "TreeNode.h"
#ifndef __LEAF_NODE__
#define __LEAF_NODE__
template <class KeyType, class ValType, int SIZE>
class LeafNode : public TreeNode<KeyType, ValType, SIZE>
{
public:
LeafNode()
{
nCount = 0;
};
virtual void Insert(KeyType Key, ValType Val, KeyType &ParentKey,
TreeNode<KeyType, ValType, SIZE> *&LeftChild,
TreeNode<KeyType, ValType, SIZE> *&RightChild);
protected:
ValType e_Vals[SIZE];
};
#endif
////////// Main.c for testing //////////////////
////////// Main.c for testing //////////////////
////////// Main.c for testing //////////////////
int main(int argc, char *argv[])
{
int a, b, c, d;
LeafNode<int, int, 7> TestNode;
TreeNode<int, int, 7> *e, *f;
TestNode.Insert(10, 10, a, e, f);
return 0;
}
Tayfun Ozdemir