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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:44:25+00:00 2026-05-24T07:44:25+00:00

I’m a bit new to c++0x, can anyone explain to me why the following

  • 0

I’m a bit new to c++0x, can anyone explain to me why the following fail to compile:

void memory_leak_report()
{
    std::cout.flags(std::ios::showbase);
    std::for_each(allocation_records.begin(), allocation_records.end(),
                  [] (const struct memory_leak_report& rec) {
                      std::cout << "memory leak at: " << rec.file << ": line " << rec.line
                                << std::hex << ", address: " << rec.address << std::dec
                                << ", size:" << rec.size << std::endl;
    });
}

where allocation_records is defined as: std::list<struct memory_allocation_record> allocation_records and memory_allocation_record is a simple C style data structure.

struct memory_allocation_record {
    const char *func;
    const char *file;
    unsigned int line;
    unsigned int size;
    unsigned long address;
};

I’ve tried compiling it with: g++ -Wall -g -o alloc main.cpp -std=c++0x

The errors I get are:
In function ג_Funct std::for_each(_IIter, _IIter, _Funct) [with _IIter = std::_List_iterator, _Funct = memory_leak_report()::]

error: no match for call to (memory_leak_report()::) (memory_allocation_record&)

note: candidates are: void (*)(const memory_leak_report()::memory_leak_report&)

  • 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-24T07:44:25+00:00Added an answer on May 24, 2026 at 7:44 am

    First, In C++, you don’t need to (and it’s usually considered bad style) put struct in front of uses of a struct. Just const memory_leak_report& would do fine.

    Second, you tell us how the struct memory_allocation_record is defined, but the lambda takes a memory_leak_report as its parameter, which, as far as I can see, is a function.

    is that your error? Was the lambda supposed to take a memory_allocation_record instead?

    Which brings us to the last point, of course. If you get an error, don’t you think it’d be relevant to tell us what that error is? Otherwise, we have to guess at what we think might be a problem in your code.

    Edit
    Ok, as I suspected, that seems to be the problem. I can recommend actually reading the compiler’s errors. That’s why they’re there. 😉

    Take the first line of the error:

    /usr/include/c++/4.5/bits/stl_algo.h:4185:2: error: no match for call to ג(memory_leak_report()::<lambda(const memory_leak_report()::memory_leak_report&)>) (memory_allocation_record&)
    

    strip away the irrelevant bits:

    no match for call to <somethingwithlambdas> (memory_allocation_record&)
    

    Now, because this is a lambda, the type is a bit hairy, but ultimately, it’s talking about a function call, and so the last parentheses describe the parameter. In other words, it tries to call a function with a memory_allocation_record& as its parameter, but is unable to find a matching function.

    Instead, it found the candidate described in the second line:

    candidates are: void (*)(const memory_leak_report()::memory_leak_report&) <conversion>
    

    So, the candidate it actually found takes a const memory_leak_report& as its parameter.

    Now you just need to compare the two. What could it mean, when the compiler tries to pass a memory_allocation_record& to a function that expects a const memory_leak_report&?

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

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.