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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:29:50+00:00 2026-06-11T08:29:50+00:00

more to the point, what’s wrong with this code: #include <assert.h> #include <functional> using

  • 0

more to the point, what’s wrong with this code:

#include <assert.h>
#include <functional>
using namespace std;

    template< class BaseObjectId >
    class Check
    {
    protected:
        Check( function<bool()> const f ) { assert( f() ); }
    };

    template< int tpMinValue, int tpMaxValue >
    class IntegerSubrange
        : private Check< IntegerSubrange< tpMinValue, tpMaxValue > >
    {
    private:
        int     value_;

    public:
        enum :int { minValue = tpMinValue, maxValue = tpMaxValue };

        static bool rangeContains( int const x )
        {
            return (minValue <= x && x <= maxValue);
        }

        operator int() const
        {
            return value_;
        }

        void operator/=( int const rhs )
        {
            value_ /= rhs;
            assert( rangeContains( value_ ) );
        }

        explicit IntegerSubrange( int const value )
            : Check< IntegerSubrange< tpMinValue, tpMaxValue > >(
                [=]() -> bool { return rangeContains( value ); }
                )
            , value_( value )
        {}
    };

int main() {}

Visual C++ reports a syntax error:

foo.cpp
foo.cpp(41) : error C2059: syntax error : ')'
        foo.cpp(44) : see reference to class template instantiation 'IntegerSubrange' being compiled
foo.cpp(42) : error C2059: syntax error : ','
foo.cpp(43) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
  • 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-11T08:29:52+00:00Added an answer on June 11, 2026 at 8:29 am

    To summarize the comments: The questioner’s code is valid. Apparently some compilers older than GCC 4.4 or Visual C++ 2011 will reject it, due to those compilers’ incomplete support for C++11-style lambdas. But modern compilers (and certainly any compiler that claims to support the new C++11 standard) should handle it just fine.

    To answer your question literally: In a ctor-initializer-list, the same identifiers are available (and refer to the same things) as they would refer to if you moved them inside the curly braces of the constructor function itself. In particular, this means that you can do

    class C {
        const char *p_ = "foo";
        char c_;
        C(int): p_(__func__) { }      // referring to "__func__"
        C(double): c_(*this->p_) { }  // referring to "this"
    };
    

    Here’s what the Standard has to say on the subject:

    Names in the expression-list or braced-init-list of a mem-initializer
    are evaluated in the scope of the constructor for which the
    mem-initializer is specified. … [Note: Because the mem-initializer
    are [sic] evaluated in the scope of the constructor, the this pointer can be
    used in the expression-list of a mem-initializer to refer to the
    object being initialized. —end note]    (N3337 §12.6.2 #12)

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

Sidebar

Related Questions

How? More to the point... this: $url = 'http://php.net/manual/en/class.domelement.php'; $client = new Zend_Http_Client($url); $response
My knowledge of C++ at this point is more academic than anything else. In
1 The following is more to point out to the code devs an issue
More than one time I have encountered the following problem when building code with
More C++ learning questions. I've been using vectors primarily with raw pointers with a
Is there anyway of configuring tomcat to point more than one context at a
This is actually comes from a specific WordPress issue but there's a more general
Edit -- I'll try to make my question more to the point I am
I want to use the conditional attribute on a class, or more to the
I have a set of points like this (that I have clustered using R):

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.