Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Linker Error C++ Visual Studios Hey guys I am having difficulty linking my heade

ID: 673917 • Letter: L

Question

Linker Error C++ Visual Studios

Hey guys I am having difficulty linking my header (.h) file with my source file (.cpp). I am getting the error message "unresolved external symbol private: void_thiscall...". I have put the correct libraries in the (.h) file but it still seems to give me the error. This is my source and header file. Thanks in advance.

SOURCE: All_bout_trees.cpp

// This program builds a binary tree with 5 nodes.
// The nodes are displayed with inorder, preorder,
// and postorder algorithms.
#include <iostream>
#include "Btrees.h"
using namespace std;

int main()
{
   IntBinaryTree tree;
   cout << "Inserting the numbers 5 8 3 12 9. ";
   tree.insert(5);
   tree.insert(8);
   tree.insert(3);
   tree.insert(12);
   tree.insert(9);
  
       cout << "Inorder traversal: ";
   tree.showInOrder();
  
       cout << " Preorder traversal: ";
       tree.showPreOrder();
  
       cout << " Postorder traversal: ";
       tree.showPostOrder();
   return 0;
   }

//**************************************************
// This version of insert inserts a number into *
// a given subtree of the main binary search tree. *
//**************************************************
void IntBinaryTree::insert(TreeNode * &tree, int num)
{
   // If the tree is empty, make a new node and make it
   // the root of the tree.
   if (!tree)
   {
       tree = new TreeNode(num);
       return;

   }

   // If num is already in tree: return.
   if (tree->value == num)
       return;

   // The tree is not empty: insert the new node into the
   // left or right subtree.
   if (num < tree->value)
       insert(tree->left, num);
   else
       insert(tree->right, num);

}

//***************************************************
// destroySubTree is called by the destructor. It *
// deletes all nodes in the tree. *
//***************************************************
void IntBinaryTree::destroySubtree(TreeNode *tree)
{
   if (!tree) return;
   destroySubtree(tree->left);
   destroySubtree(tree->right);
   // Delete the node at the root.
   delete tree;
}

//***************************************************
// searchNode determines if a value is present in *
// the tree. If so, the function returns true. *
// Otherwise, it returns false. *
//***************************************************
bool IntBinaryTree::search(int num)
{
   TreeNode *tree = root;

   while (tree)
   {
       if (tree->value == num)
           return true;
       else if (num < tree->value)
           tree = tree->left;
       else
           tree = tree->right;
   }
   return false;
}


//********************************************
// remove deletes the node in the given tree *
// that has a value member the same as num. *
//********************************************
void IntBinaryTree::remove(TreeNode *&tree, int num)
{
   if (tree == NULL) return;
   if (num < tree->value)
       remove(tree->left, num);
   else if (num > tree->value)
       remove(tree->right, num);
   else
       // We have found the node to delete.
       makeDeletion(tree);
}

//***********************************************************
// makeDeletion takes a reference to a tree whose root *
// is to be deleted. If the tree has a single child, *
// the tree is replaced by the single child after the *
// removal of its root node. If the tree has two children *
// the left subtree of the deleted node is attached at *
// an appropriate point in the right subtree, and then *
// the right subtree replaces the original tree. *
//***********************************************************
void IntBinaryTree::makeDeletion(TreeNode *&tree)
{
   // Used to hold node that will be deleted.
   TreeNode *nodeToDelete = tree;

   // Used to locate the point where the
   // left subtree is attached.
   TreeNode *attachPoint;

   if (tree->right == NULL)
   {
       // Replace tree with its left subtree.
       tree = tree->left;
   }
   else if (tree->left == NULL)
   {
       // Replace tree with its right subtree.
       tree = tree->right;
   }
   else
       //The node has two children
   {
       // Move to right subtree.
       attachPoint = tree->right;

       // Locate the smallest node in the right subtree
       // by moving as far to the left as possible.
       while (attachPoint->left != NULL)
           attachPoint = attachPoint->left;

       // Attach the left subtree of the original tree
       // as the left subtree of the smallest node
       // in the right subtree.
       attachPoint->left = tree->left;
       // Replace the original tree with its right subtree.
       tree = tree->right;

   }

   // Delete root of original tree
   delete nodeToDelete;

}

//*********************************************************
// This function displays the values stored in a tree *
// in inorder. *
//*********************************************************
void IntBinaryTree::displayInOrder(TreeNode *tree)
{
   if (tree)
   {
       displayInOrder(tree->left);
       cout << tree->value << " ";
       displayInOrder(tree->right);
   }
}

//*********************************************************
// This function displays the values stored in a tree *
// in inorder. *
//*********************************************************
void IntBinaryTree::displayPreOrder(TreeNode *tree)
{
   if (tree)
   {
       cout << tree->value << " ";
       displayPreOrder(tree->left);
       displayPreOrder(tree->right);
   }
}

//*********************************************************
// This function displays the values stored in a tree *
// in postorder. *
//*********************************************************
void IntBinaryTree::displayPostOrder(TreeNode *tree)
{
   if (tree)
   {
       displayPostOrder(tree->left);
       displayPostOrder(tree->right);
       cout << tree->value << " ";
   }
}

HEADER: Btrees.h

#ifndef INTBINARYTREE_H
#define INTBINARYTREE_H

class IntBinaryTree
{
private:
   // The TreeNode class is used to build the tree.
   class TreeNode
   {
       friend class IntBinaryTree;
       int value;
       TreeNode *left;
       TreeNode *right;
       TreeNode(int value1, TreeNode *left1 = NULL,TreeNode *right1 = NULL)
       {
           value = value1;
           left = left1;
           right = right1;
       }
   };

   TreeNode *root; // Pointer to the root of the tree
   // Various helper member functions.
   void insert(TreeNode *&, int);
   void destroySubtree(TreeNode *);
   void remove(TreeNode *&, int);
   void makeDeletion(TreeNode *&);
   void displayInOrder(TreeNode *);
   void displayPreOrder(TreeNode *);
   void displayPostOrder(TreeNode *);
  
  

public:
   // These member functions are the public interface.
   IntBinaryTree() // Constructor
   {
       root = NULL;
   }
   ~IntBinaryTree() // Destructor
   {
       destroySubtree(root);
   }
   void insert(int num)
   {
       insert(root, num);
   }
   bool search(int);
   void remove(int num)
   {
       remove(root, num);
   }
   void showInOrder(void)
   {
       displayInOrder(root);
   }
   void showPreOrder()
   {
       displayPreOrder(root);
   }
   void showPostOrder()
   {
       displayPostOrder(root);
   }

};
#endif

Explanation / Answer

Since you are using

using namespace std;

you must not use .h extention while including "Btrees" write it like this

#include "Btress"

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote