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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:25:27+00:00 2026-06-11T12:25:27+00:00

Got this ScopeExit class off code-project but it would not build on GCC 4.5.3.

  • 0

Got this ScopeExit class off code-project but it would not build on GCC 4.5.3. Appreciate any help.

class ScopeExit : private boost::noncopyable
{
    typedef std::function<void()> func_t;

public:
    ScopeExit(func_t&& f) : func(f) {}
    ~ScopeExit() { func(); }

private:
    // no default ctor
    ScopeExit();

    // Prohibit construction from lvalues.
    ScopeExit(func_t&);

    // Prohibit new/delete.
    void* operator new(size_t);
    void* operator new[](size_t);
    void operator delete(void *);
    void operator delete[](void *);

    const func_t func;
};


ScopeExit exit = [&]() { };

gcc 4.5.3 errors:

In member function ‘void test()’:
error: conversion from ‘test()::<lambda()>’ to non-scalar type ‘ScopeExit’ requested

Edit:

ScopeExit exit([&]() { }); // this works
  • 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-11T12:25:28+00:00Added an answer on June 11, 2026 at 12:25 pm

    It’s copy/move initialization. Your copy c-tor is deleted, move c-tor is deleted too.

    n3337 12.8/9

    If the definition of a class X does not explicitly declare a move constructor, one will be implicitly declared
    as defaulted if and only if

    — X does not have a user-declared copy constructor,

    — X does not have a user-declared copy assignment operator,

    — X does not have a user-declared move assignment operator,

    — X does not have a user-declared destructor, and

    — the move constructor would not be implicitly defined as deleted.

    Have no ideas why first case doesn’t work, but this case works fine

    template<typename T>
    ScopeExit(T&& f) : func(std::move(f)) {}
    ScopeExit(ScopeExit&& rhs) : func(std::move(rhs.func)) { }]
    

    EDIT.

    When we use copy-initialization of variable of class-type only standard and elipsis implicit conversions are used. Conversion from lambda to function pointer or from function pointer to std::function is user-defined conversion and not used.

    n3337 8.5/16

    The semantics of initializers are as follows. The destination type is the type of the object or reference being
    initialized and the source type is the type of the initializer expression. If the initializer is not a single (possibly
    parenthesized) expression, the source type is not defined.

    If the destination type is a (possibly cv-qualified) class type:

    Otherwise (i.e., for the remaining copy-initialization cases), user-defined conversion sequences
    that can convert from the source type to the destination type or (when a conversion function
    is used) to a derived class thereof are enumerated as described in 13.3.1.4, and the best one is
    chosen through overload resolution (13.3). If the conversion cannot be done or is ambiguous, the
    initialization is ill-formed.

    n3337 13.3.1.4/1

    Under the conditions specified in 8.5, as part of a copy-initialization of an object of class type, a user-defined
    conversion can be invoked to convert an initializer expression to the type of the object being initialized.
    Overload resolution is used to select the user-defined conversion to be invoked. Assuming that “cv1 T” is
    the type of the object being initialized, with T a class type, the candidate functions are selected as follows:

    — The converting constructors (12.3.1) of T are candidate functions.

    1. In both cases, the argument list has one argument, which is the initializer expression. [ Note: This argument
      will be compared against the first parameter of the constructors and against the implicit object parameter
      of the conversion functions. — end note ]

    n3337 13.3.2

    1. From the set of candidate functions constructed for a given context (13.3.1), a set of viable functions is
    chosen, from which the best function will be selected by comparing argument conversion sequences for the
    best fit (13.3.3). The selection of viable functions considers relationships between arguments and function
    parameters other than the ranking of conversion sequences.

    Second, for F to be a viable function, there shall exist for each argument an implicit conversion se-
    quence (13.3.3.1) that converts that argument to the corresponding parameter of F.

    n3337 13.3.3.1/4

    However, when considering the argument of a constructor or user-defined conversion function that is a
    candidate by 13.3.1.3 when invoked for the copying/moving of the temporary in the second step of a class
    copy-initialization, by 13.3.1.7 when passing the initializer list as a single argument or when the initializer
    list has exactly one element and a conversion to some class X or reference to (possibly cv-qualified) X is
    considered for the first parameter of a constructor of X, or by 13.3.1.4, 13.3.1.5, or 13.3.1.6 in all cases, only
    standard conversion sequences and ellipsis conversion sequences are considered.

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

Sidebar

Related Questions

Got this line of code here but its not working. private void Button_Click(object sender,
I got this code from our frontend guy for headings: <h2 class=headline><span>Foobar</span></h2> The span
Got this error today while trying to build a project with checkstyle. This works
I got this from a site which was explaining sorting. But i could not
Got this code in C#: using System; public class Listener{ public static void Main(){
I got this html code: <div class=imgContent> <div id=galleryImg> <img class=img_<?php echo $this->id ?>_1
Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
Got this error trying to do a new project with rails 3.2. haml issue
got this code from a website that helped me in creating buttons and stuff.
I got this example from one StackOverflow question that was asked but I couldn't

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.