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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:41:54+00:00 2026-06-05T00:41:54+00:00

I’m trying to implement my own Set template, and have issues with trying to

  • 0

I’m trying to implement my own Set template, and have issues with trying to do a breadth- first search using my Queue template that works independently.

The weird part is that I get this error in my Set template when trying to compile. Why can’t it convert from one pointer to a different one that is the same data type?

error C2440: '=' : cannot convert from 'Set<T>::Node<T> *' to 'Set<T>::Node<T> *'
      with
      [
          T=std::string
      ]
      Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
      c:\users\programming\Set\Set.h(96) : while compiling class template member function 'void Set<T>::print(Set<T>::Node<T> *)'
      with
      [
          T=std::string
      ]
      c:\users\programming\Set\main.cpp(13) : see reference to class template instantiation 'Set<T>' being compiled
      with
      [
          T=std::string
      ]

Queue Class Template

template <typename T>
class Queue
...
T* front()
{
    if (first != NULL)
        return first->item;
    else
        return NULL;
}

Set Class Template

template <typename T>
Class Set
...
Queue<Node<T> *> q;
void print(Node<T> *p)
{
    q.push(p);
    while (p != NULL)
    {
        cout << p->item << "(" << p->height << ") ";
        if (p->left != NULL)
            q.push(p->left);
        if (p->right != NULL)
            q.push(p->right);
        if (!q.size())
        {
            // Error is at this line
            p = q.front();
            q.pop();
        }
        else
            p = NULL;
    }
    cout << endl;
}
  • 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-05T00:41:57+00:00Added an answer on June 5, 2026 at 12:41 am

    Your Queue class is instantiated with a Node<T>* type already … you are then attempting to return a pointer to a type T from your Queue<T>::front method. If you are instantating your Queue<T> class with T=Node<T>*, then you only need to return a type T from your front method, not a T*. So change your front method signature to the following:

    template <typename T>
    class Queue
    ...
    T front()
    {
        if (first != NULL)
            return first->item;
        else
            return NULL;
    }
    

    Now this could cause you a bunch of problems if T was not a pointer type … therefore you may want to create a specialization of your Queue<T>::front method for cases where T is already a pointer type. For instance:

    //pointer-type specialization
    template<typename T>
    T Queue<T*>::front()
    {
        if (first != NULL)
            return first->item;
        else
            return NULL;
    }
    
    //non-specialized version where T is not a pointer-type
    template<typename T>
    T* Queue<T>::front()
    {
        if (first != NULL)
            return &(first->item);
        else
            return NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is

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.