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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:09:44+00:00 2026-06-13T02:09:44+00:00

I observed peculiar behavior in g++4.6.3. When creating a temporary by calling class constructor

  • 0

I observed peculiar behavior in g++4.6.3. When creating a temporary by calling class constructor File(arg) the compiler chooses to ignore the existence of arg and parse the expression as File arg;

  • Why is the member name ignored?
  • What does the standard say?
  • How to avoid it? (Without using new {} syntax)
  • Is there a related compiler warning? (I could use an arbitrary string arg and it would still work quietly)

Code:

#include <iostream>

class File {
public:
    explicit File(int val) : m_val(val) { std::cout<<"As desired"<< std::endl; }
    File() : m_val(10) { std::cout<< "???"<< std::endl;}

private:
    int m_val;
};

class Test {
public:
    void RunTest1() { File(m_test_val); }
    void RunTest2() { File(this->m_test_val); }
    void RunTest3() { File(fhddfkjdh); std::cout<< "Oops undetected typo"<< std::endl; }
private:
    int m_test_val;
};

int main()
{
    Test t;
    t.RunTest1();
    t.RunTest2();
    t.RunTest3();
    return 0;
}

Output:

$ ???
$ As desired
$ Oops undetected typo
  • 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-13T02:09:45+00:00Added an answer on June 13, 2026 at 2:09 am

    The compiler treats the line:

    File(m_test_val);
    

    as

    File m_test_val;
    

    so you’re actually creating a named object called m_test_val using the default constructor. Same goes for File(fhddfkjdh).

    The solution is File(this->m_test_val) – this tells the compiler that you want to use the member to create create a named object. Another would be to name the object – File x(m_test_val).

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

Sidebar

Related Questions

With great surprised I observed the following behavior today: Given a class class Foo
I observed some unexpected behavior with TTLauncherView from Three20. After creating a standard view
I've observed a difference in behavior between the new library in Visual Studio 11
I recently observed a very weird problem with MediaPlayer playing an mp3 file. I'm
I observed a strange behavior == operator in java. I am trying to print
I observed some strange behavior regarding injecting EntityManager. Following is stripped down version of
I observed the following behavior while working with the perl code base (on branch
Here is something I observed across various compilers. It seems there are compiler bugs.
I've observed a strange behavior by parsing a string to a XElement. First, here
I have observed a strange behavior, I have a XAML Combobox (SilverLight4) declaration with

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.