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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:14:29+00:00 2026-06-03T09:14:29+00:00

Let’s say I have a class which will be used to create either tree

  • 0

Let’s say I have a class which will be used to create either tree or list structure. Let’s call it

template <typename K, typename V>
class Node{
  // some data
  Node<K,V>* next;
  Node() {
    next = static_cast<Node<K,V>*>( malloc( sizeof(Node<K,V>) ));
  }
};

By doing this I get a following compiler error:

there are no arguments to ‘malloc’ that depend on a template
parameter, so a declaration of ‘malloc’ must be available (if you use
‘-fpermissive’, G++ will accept your code, but allowing the use of an
undeclared name is deprecated)

Is there any way to use malloc in such a way without having to use deprecated code? I want to use malloc instead of new because I’d like to do some more advanced memory management up there.

  • 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-03T09:14:30+00:00Added an answer on June 3, 2026 at 9:14 am

    The compiler error is telling you that it does not have a declaration of what malloc is. You are missing the include that declares that function.

    Other than that, the approach is broken. You are writing a generic tree, but because of the use of malloc you are limiting the use to POD types (I am assuming that K and V are stored in the Node). You should use new instead that will call the constructor for the type, not just allocate memory.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's say I have an image called hello.png with dimensions 200x100 . I create
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have a list of objects TheListOfObjects. If I write this: TheListOfObjects
Let's say I have this string which I want to put in a multidimensional
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have an string variable called *magic_string* which value is set to
Let's say I have this HTML: <div> <div class=ClassA></div> <div class=ClassX></div> <div class=ClassB></div> <div

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.