Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 86377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:14:11+00:00 2026-05-10T22:14:11+00:00

hI, I’m trying to get this code from Larry Nyhoff’s book to compile in

  • 0

hI, I’m trying to get this code from Larry Nyhoff’s book to compile in Bloodshed. It’s actually been taken word for word from the author’s website, though I declared it on .cpp instead of .h (the .h file ain’t working with the tester application).

http://cs.calvin.edu/activities/books/c++/ds/2e/SourcePrograms/Chap12/

The search(const DataType & item) function is what’s giving me grief. The compiler error says:

In member function `bool BST<DataType>::search(const DataType&) const':  expected `;' before 'locptr'  `locptr' undeclared (first use this function)  

What I’m I missing here?

 #include <iostream>  #ifndef BINARY_SEARCH_TREE #define BINARY_SEARCH_TREE   template <typename DataType> class BST {  public:   /***** Function Members *****/   BST();    bool empty() const;    bool search(const DataType & item) const;    void insert(const DataType & item);    void remove(const DataType & item);    void inorder(std::ostream & out) const;    void graph(std::ostream & out) const;    private:   /***** Node class *****/   class BinNode    {    public:     DataType data;     BinNode * left;     BinNode * right;      // BinNode constructors     // Default -- data part is default DataType value; both links are null.     BinNode()     : left(0), right(0)     {}      // Explicit Value -- data part contains item; both links are null.     BinNode(DataType item)     : data(item), left(0), right(0)     {}   }; //end inner class  typedef BinNode * BinNodePointer;     /***** Private Function Members *****/   void search2(const DataType & item, bool & found,                BinNodePointer & locptr, BinNodePointer & parent) const;  /*------------------------------------------------------------------------    Locate a node containing item and its parent.     Precondition:  None.    Postcondition: locptr points to node containing item or is null if         not found, and parent points to its parent.#include <iostream>  ------------------------------------------------------------------------*/    void inorderAux(std::ostream & out,                    BST<DataType>::BinNodePointer subtreePtr) const;   /*------------------------------------------------------------------------     Inorder traversal auxiliary function.      Precondition:  ostream out is open; subtreePtr points to a subtree          of this BST.     Postcondition: Subtree with root pointed to by subtreePtr has been         output to out.  ------------------------------------------------------------------------*/    void graphAux(std::ostream & out, int indent,                       BST<DataType>::BinNodePointer subtreeRoot) const;   /*------------------------------------------------------------------------     Graph auxiliary function.      Precondition:  ostream out is open; subtreePtr points to a subtree          of this BST.     Postcondition: Graphical representation of subtree with root pointed          to by subtreePtr has been output to out, indented indent spaces.  ------------------------------------------------------------------------*/   /***** Data Members *****/   BinNodePointer myRoot;   }; // end of class template declaration  //--- Definition of constructor template <typename DataType> inline BST<DataType>::BST() : myRoot(0) {}  //--- Definition of empty() template <typename DataType> inline bool BST<DataType>::empty() const { return myRoot == 0; }  //--- Definition of search() template <typename DataType> bool BST<DataType>::search(const DataType & item) const {    BST<DataType>::BinNodePointer locptr = myRoot; //**THIS FAILS, WHY?**//    bool found = false;    while (!found && locptr != 0)    {       if (item < locptr->data)       // descend left         locptr = locptr->left;       else if (locptr->data < item)  // descend right         locptr = locptr->right;       else                           // item found         found = true;    }    return found; }     #endif 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:14:12+00:00Added an answer on May 10, 2026 at 10:14 pm

    Put a typename before the declaration:

    typename BST<DataType>::BinNodePointer locptr = myRoot; 

    The point is that due to potential template specialization, the compiler cannot know that the dependent identifier BinNodePointer identifies a type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What you're attempting to do is pass credentials via HTTP… May 12, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer The blog post linked by Dan shows you how to… May 12, 2026 at 1:06 am
  • Editorial Team
    Editorial Team added an answer The pythonic thing to do is to raise and handle… May 12, 2026 at 1:06 am

Related Questions

HI, I am new to the scrum methodology and looking for some help to
HI, I have 3 tables: Clips , Books and relationships between ClipBook Problem is:
hI, I'm trying to get this code from Larry Nyhoff's book to compile in
HI, I m doing the folling stuff in the jsp code I need to
Hi*, I am using the .NET Compact framework Remote Performance Monitor from the .net

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.