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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:19:25+00:00 2026-06-04T19:19:25+00:00

My question is about the new C++11 feature Delegating Constructors. So I have two

  • 0

My question is about the new C++11 feature Delegating Constructors. So I have two similar ctors in my class and I would like to simplify their implementation. The problem that they both have structures as a parameter and when I tried to delegate them, a compiler error occured:

error: type ‘MyClass’ is not a direct base of ‘MyClass’

So here is before:

MyClass::MyClass ( const timeval & TV ) :
      Seconds ( TV.tv_sec),
      USeconds ( TV.tv_usec ),
{
}

MyClass::MyClass ( const timespec & TS ) :
        Seconds ( TS.tv_sec),
        USeconds ( TS.tv_nsec * 1000 ),
{
}

After:

MyClass::MyClass ( const timeval & TV ) :
      MyClass ( timeval { TV.tv_sec, TV.tv_usec/1000 } )
{
}

MyClass::MyClass ( const timespec & TS ) :
        Seconds ( TS.tv_sec),
        USeconds ( TS.tv_nsec * 1000 ),
{
}

Does anybody know how can I call the second ctor from the first one correctly?

  • 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-04T19:19:27+00:00Added an answer on June 4, 2026 at 7:19 pm

    Besides the obvious error (you are trying to delegate to the same constructor) the code is correct and should work on g++4.7

    MyClass::MyClass ( const timeval & TV ) :
          MyClass ( timespec { TV.tv_sec, TV.tv_usec/1000 } )
    {
    }
    
    MyClass::MyClass ( const timespec & TS ) :
            Seconds ( TS.tv_sec),
            USeconds ( TS.tv_nsec * 1000 ),
    {
    }
    

    It might be an issue with your compiler/version.

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

Sidebar

Related Questions

Today I have another specific question about a new feature in windows 7 called
I'm thinking about offering a new feature to Java and I would like to
I have a general question about the new Django 1.3 static file framework. I
I have been asked to post a new question about how to correctly sort
Question about subclassing in matlab, under the new class system. I've got class A
Im new to rails and have a question about accessing relations of relations in
I am quite new to R and have a question about loops In my
everybody! I have a new question about Kohana 3, or rather about a module
eternal question about twoForms: frm02 frm02 = new frm02(); frm02.Text = Objects; ds02 =
I am new to D3 and just had a quick question about tick labels

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.