我打算在C++中开发bptree。我在C++编程中很新,并且遇到了这个错误,我不确定它们是什么。 LNK2005和LNK1169错误在c + +
我有四个文件: Node.h
#ifndef NODE_HEADER
#define NODE_HEADER
#include <string>
#include <map>
using namespace std;
class Node {
bool leaf;
Node** kids;
map<int, string> value;
int keyCount;//number of current keys in the node
public:
Node(int order);
void printNodeContent(Node* node);
friend class BpTree;
};
#endif
Node.cpp
#include <cstdio>
#include <iostream>
#include "Node.h"
//constructor;
Node::Node(int order) {
this->value = {};
this->kids = new Node *[order + 1];
this->leaf = true;
this->keyCount = 0;
for (int i = 0; i < (order + 1); i++) {
this->kids[i] = NULL;
}
}
void Node::printNodeContent(Node* node) {
map<int,string> values = node->value;
for (auto pval : values) {
cout << pval.first << "," ;
}
cout << endl;
}
void main() {
}
BpTree.h
#ifndef BPTREE_HEADER
#define BPTREE_HEADER
#include "Node.cpp"
class BpTree
{
Node *root;
Node *np;
Node *x;
public:
int order;
BpTree();
~BpTree();
BpTree(int ord);
int getOrder();
Node* getRoot();
bool insert(int key, string value);
};
#endif
BpTree.cpp
#include<stdio.h>
#include<conio.h>
#include<iostream>
#include<string>
#include "BpTree.h"
BpTree::BpTree(int ord)
{
root = new Node(ord);
order = ord;
np = NULL;
x = root;
}
BpTree::BpTree()
{
}
BpTree::~BpTree()
{
}
int BpTree::getOrder()
{
return order;
}
Node* BpTree::getRoot()
{
return root;
}
bool BpTree::insert(int key, string value) {
int order = getOrder();
if (x == NULL) {
x = root;
}
else {
if (x->leaf && x->keyCount <= order) {
x->value.insert({ key, value });
}
}
return false;
}
这是什么,我在这里失踪。我试图只包含.h文件或.cpp文件一次。但仍然得到这个错误。如果任何人有任何建议如何解决这个问题,我真的很感激它。
您不应该在BpTree.h文件中包含Node.cpp include Node.h。 – Rob