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

  • Home
  • SEARCH
  • 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 8938073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:32:27+00:00 2026-06-15T10:32:27+00:00

I am writing a function to copy a templated binary tree. So far, I

  • 0

I am writing a function to copy a templated binary tree. So far, I have this:

template <typename Item, typename Key>
Node* BSTree<Item,Key>::copy(Node* root) {
    if(root == NULL) return NULL;

    Node* left;
    Node* right;
    Node* to_return;

    left = copy(root->left());
    right = copy(root->right());

    to_return = new Node(root->data());
    to_return->left() = left;
    to_return->right() = right;

    return to_return;
}

But when I try to compile the program, I get multiple errors that I can’t figure out how to solve. All of them occur on the line right after the template declaration.

1) error C2143:syntax error: missing’;’ before’*’

2) error C4430: missing type specifier – int assumed

3) error C2065: ‘Item’ : undeclared identifier

4) error C2065: ‘Key’ : undeclared identifier

All of my other functions in the program compile correctly and have no problem with the template so I’m not really sure why this one does. It is already declared in the header file and definitely has a return type assigned to it so I’m stumped.

  • 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-06-15T10:32:29+00:00Added an answer on June 15, 2026 at 10:32 am

    Is Node a subclass of BSTree? If so, it’s not in scope in the return type and so you have to qualify it:

    template <typename Item, typename Key>
    typename BSTree<Item,Key>::Node* BSTree<Item,Key>::copy(Node* root)
    

    If you have C++11 then auto works too:

    template <typename Item, typename Key>
    auto BSTree<Item,Key>::copy(Node* root) -> Node
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing matrix classes. Take a look at this definition: template <typename T,
I am writing a function short getBits(short data, int p, int n) I have
Consider the following function template: template<typename T> void Foo(T) { // ... } Pass-by-value
I'm writing the following function to format some text from a file object 'item':
I'm writing a template function which should swap two elements of a boost::mpl::vector (similarly
I am writing my own string copy function. The following works: char *src, *dest;
I am having problem in writing copy constructor for pointers to objects. This is
So in writing a C++ template class, I have defined a method that returns
I was just writing a Matlab function and wanted to copy and paste what
I am currently writing a MEX function that will have to work with a

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.