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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:18:20+00:00 2026-05-30T06:18:20+00:00

I hope the following snippet explains it all: struct TBase { virtual void f()

  • 0

I hope the following snippet explains it all:

struct TBase {
  virtual void f() {}
};

struct TDerived : public TBase {
    TDerived() {
      /* These are all fine either under GCC 4.4.3, ICC 12 and Comeau online: */
      f();
      this->f();
      TBase::f();
      this->TBase::f();

      /* This one fails under Comeau: */
      TBase::TBase();

      /* While this one fails in every case: */
      //this->TBase::TBase();

      /* e.g. GCC says:
         test.cpp: In constructor ‘TDerived::TDerived()’:
         test.cpp:17: error: invalid use of ‘struct TBase’  */
    }
    void f() {}
};

The question is: why? (i.e. why is TBase::TBase() wrong, according to Comeau C++? Why is this->TBase::TBase() even wronger?)

  • 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-30T06:18:21+00:00Added an answer on May 30, 2026 at 6:18 am

    Because you cannot call any constructor directly (§12.1 (2) ISO/IEC 14882:2003(E)). If you want to call a base class constructor, you will have to do so in the initializer list, i.e.:

    TDerived() : TBase() {
    }
    

    The main reason for this is that by the time control reaches the first executable code line of your derived constructor, it is guaranteed that the base class object is already fully constructed (§12.6.2 (5) and (6) ISO/IEC 14882:2003(E)). Since constructors are commonly used for resource acquisition (i.e. RAII), it would be an error if it was allowed to “double”-construct an object.

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

Sidebar

Related Questions

I just hope the following doesn't seem to you like redundant jabber :) Anyway,
i'm trying to do the following hope there's a reg_ex expert around to shed
I hope the title and following text are clear, I'm not very familiar with
How can I do this? (The following code does NOT work, but I hope
Hope you're having a good Friday and stuff... okay, so here's my question: All
I am having problems compiling the following snippet int temp; vector<int> origins; vector<string> originTokens
I'm using Fancybox and Zend. Hope the following is clear. On www.example.com/template/edit/id/3 I have
I hope you could help me with the following question: A user clicks a
I hope someone can help me with a solution to the following error. The
The following is a theoretical question, that I hope someone will be able to

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.