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 6845421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:29:55+00:00 2026-05-27T00:29:55+00:00

I have a Binary-Tree class template with several public and private member functions. When

  • 0

I have a Binary-Tree class template with several public and private member functions. When the member functions are both defined and implemented inside the class template, it compiles correctly and functions as expected. However, when I move those functions outside of the main class template, I get a multiplicity of errors.

  • According to this reference, class template functions cannot be made external because the templates are compiled at run-time. http://www.codeguru.com/forum/archive/index.php/t-333284.html

  • However this MSDN article suggests that “member templates can also be defined outside of a class.” http://msdn.microsoft.com/en-us/library/swta9c6e(v=vs.80).aspx

Is there something I am missing here?

template <class type>
class BinaryTree{
private:
    Node<type>* root;
    void internalTraverse(Node<type>* n){}
    ......
public:
    ......
};

template <class type>
void BinaryTree<type>::internalTraverse(Node<type>* n){
    if (n == NULL){
        return;
    }
    internalTraverse(n->left);          //  <- This declaration has no storage type or identifier
    cout << "Node: " << n->data << endl;//  Ditto
    internalTraverse(n->right);         //  Ditto
};
......

For full disclosure: This is part of a homework assignment. However, its not directly related to the purpose of the assignment — more of a tangential problem

  • 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. Editorial Team
    Editorial Team
    2026-05-27T00:29:55+00:00Added an answer on May 27, 2026 at 12:29 am

    You defined the member function both inline and out-of-line, so that’s multiple. The following compiles:

    #include <iostream>
    
    template <typename> class Node;
    
    template <class type>
    class BinaryTree{
    private:
      Node<type>* root;
      void internalTraverse(Node<type>* n);  // <--- no definition!
    };
    
    template <class type>
    void BinaryTree<type>::internalTraverse(Node<type>* n){
      if (n == NULL){
        return;
      }
      internalTraverse(n->left);identifier
      std::cout << "Node: " << n->data << std::endl;
      internalTraverse(n->right);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a binary tree class that is created with a root node and
Im having a problem with python.. I have a binary tree node type: class
I have a binary tree of functions and terminal values. I'd like to print
I'm implementing template binary tree in cpp with eclipse and I have trouble. template
I have a Binary Search Tree as a derived class from a Binary Tree,
I have a binary tree where each node can have a value. I want
I have a Binary tree for a mathematical expression(infix), i want to convert directly
I have a binary tree in unordered list that looks like this: <ul> <li>1
I have problems building a binary tree from the bottom up. THe input of
I have a very simple binary tree structure, something like: struct nmbintree_s { unsigned

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.