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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:51:11+00:00 2026-05-29T07:51:11+00:00

I was writing a function foo() which takes 2 const char* s as arguments,

  • 0

I was writing a function foo() which takes 2 const char*s as arguments, pBegin and pEnd. foo() is passed a null terminated string. By default pEnd points to \0 (last character) of the string.

void foo (const char *pBegin,
          const char *pEnd = strchr(pBegin, 0))  // <--- Error
{
  ...
}

However, I get an error at above line as:

error: local variable ‘pBegin’ may not appear in this context

Why compiler doesn’t allow such operation ? What’s the potential problem ?

  • 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-29T07:51:12+00:00Added an answer on May 29, 2026 at 7:51 am

    The standard not only explicitly disallows the use of other parameters in a default argument expression, but also explains why and gives an example:

    ISO/IEC 14882:2003(E) – 8.3.6 Default arguments [dcl.fct.default]

    9. Default arguments are evaluated each time the function is called.
    The order of evaluation of function arguments is unspecified.
    Consequently, parameters of a function shall not be used in default
    argument expressions, even if they are not evaluated.
    Parameters of a
    function declared before a default argument expression are in scope
    and can hide namespace and class member names. [Example:

        int a;
        int f(int a, int b = a);         // error: parameter a
                                         // used as default argument
        typedef int I;
        int g(float I, int b = I(2));    // error: parameter I found
        int h(int a, int b = sizeof(a)); // error, parameter a used
                                         // in default argument
    

    —end example] …

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

Sidebar

Related Questions

Given a function that takes an output stringstream as an argument: void Foo(const std::ostringstream&
Whats this syntax useful for : function(String... args) Is this same as writing function(String[]
Suppose I'm writing a function that takes a list of integers and returns only
I'm writing a function that takes an optional list and extends it to the
I have to write a library which contains a function that takes two strings
I'm writing an extension method for Array which accepts a function and then call
I'm writing a function that fishes out the src from the first image tag
I'm writing a function for an installer DLL to verify the Authenticode signature of
I am writing a function in Haskell that deals with numbers beyond the length
I am writing a function short getBits(short data, int p, int n) I have

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.