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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:26:03+00:00 2026-06-02T01:26:03+00:00

In C++, if you pass an anonymous object as an argument to a named

  • 0

In C++, if you pass an anonymous object as an argument to a named object method, does the anonymous object get deleted when you delete the named object?

The library I’m using for a project expects pointers to objects for most of its own objects’ methods, a la:

WContainerWidget::addWidget(WContainerWidget* widget) {/*...*/}

and in their examples they often use the new operator when constructing these objects.

WContainerWidget* aFoo = new WConainerWidget(/*args*/);
aFoo->addWidget(new WText(/*args*/));

If I delete aFoo, will the anonymous WText() object be deleted?

Am I to trust that their implementation will take care of these deletions without sorting through their source code, or should I avoid the exemplified behaviour, and explicitly name/delete everything myself?

  • 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-02T01:26:05+00:00Added an answer on June 2, 2026 at 1:26 am

    Yes the widget takes ownership and it is automatically destroyed:

    http://www.webtoolkit.eu/wt/doc/reference/html/overview.html

    When inserting a widget in the widget hierarchy, ownership is transferred to its parent in the tree.

    This is a badly defined interface. Its from the old school were people were still defining interface like C interfaces.

    The passing of pointers is silly idea as there is no concept of ownership associated with it as such modern C++ libraries have shifted to using the concept of smart pointers. This provides a mechanism to document in the code (and enforce by the compiler) the concept of pointer ownership.

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

Sidebar

Related Questions

I'm using anonymous types to pass collections of typed objects to a TemplateResolver, where
Im using JSON.NET do deserlaize an object, but i cant get it to work
Why can't you pass an anonymous method as a parameter to the BeginInvoke method?
I use an anonymous object to pass my Html Attributes to some helper methods.
Is it possible to pass an anonymous function as an argument, and have it
I want to pass anonymous property using lambda to a generic function and access
When passing a RouteValueDicitonary or anonymous object into a @Url.Action method (or any of
In jQuery plugins we can pass an anonymous object with properties. $('selecter').function({property: 'value', property:
I have a problem with passing an anonymous object as an argument in a
I have to pass return value of an anonymous function as a argument 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.