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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:57:22+00:00 2026-06-03T14:57:22+00:00

I have a template class ( Node is an inner class within a BST).

  • 0

I have a template class (Node is an inner class within a BST). It’s now time to free up the memory; Given that either the key or the value (or both) may be pointers, I must figure out how to free them if they are.

See an example:

~Node( void )
{
    if ( is_pointer< TValue >( Value ) )
    {
         delete Value;
         Value = NULL;
    }

    if ( is_pointer< TComparable >( Key ) )
    {
         delete Key;
         Key= NULL;
    }
}

The implementation behind the is_pointer< T > function works (Taken from here), however as soon as I press delete on either Key or Value, I get the following:

Error   13  error C2440: 'delete' : cannot convert from 'esc::Shader' to 'void *'   c:\programming\c++\git\escalator\engine\engine\searchtree.hpp   131
Error   14  error C2440: 'delete' : cannot convert from 'esc::ShaderComparable' to 'void *' c:\programming\c++\git\escalator\engine\engine\searchtree.hpp   137
Error   12  error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)   c:\programming\c++\git\escalator\engine\engine\searchtree.hpp   130

I’ve tried static_cast, dynamic_cast, reinterpret_cast, etc, but neither of these appear to work.

What’s a good solution?

  • 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-03T14:57:26+00:00Added an answer on June 3, 2026 at 2:57 pm
    I must figure out how to free them if they are.
    

    Don’t. Really- don’t. That’s the user’s problem- and he can supply a smart pointer if he wants this behaviour. After all, what if I want to map non-owning pointers? Or need a custom deleter?

    Also, your code does not work because you compile the dead code if branches anyway, because you did not use a specialization.

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

Sidebar

Related Questions

I have a template class with a variadic template member function that I am
I want to have a template class that looks something like what I have
I have a custom iterator template class that wraps up a std::list iterator. In
I have a BinarySearchTree that consists of nodes which are both a template class
I have defined a generic tree-node class like this: template<class DataType> class GenericNode {
I have made a template class for a node in a linked list and
I have the BST class same as in this thread BST.hpp template<class T> class
I have a template class btree and have defined a struct Node in the
I have a problem I don't really understand. I have a class Node. template<class
I have a template class defined like so: template <class T> class Command {

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.