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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:32:39+00:00 2026-05-30T12:32:39+00:00

I have an unusual problem in a large system where for various reasons I

  • 0

I have an unusual problem in a large system where for various reasons I might have to use a construct like this:

class Item
{
    int mID;
    int mID2;
    ...
    int mIDn;

public:
    Item();
    Item(const Item& Other);
    Item& operator=(const Item &Other);
};

class ItemExtension : public Item
{
     // some data
public:
     ItemExtension(const Item &Other) : Item(Other) {}
     ItemExtension(const ItemExtension &Other);
     ItemExtension& operator=(const ItemExtension& Other);
};


// client code
Item *Myitem = ItemList.ReleaseItem(index); // ownership transferred and an Item is removed from a list

std::auto_ptr<ItemExtension> ItemExt(new ItemExtension(*MyItem));
ItemExtList.push_back(ItemExt.release()); // store in std::vector and take ownership

I realize there are design flaws here, such as the chaotic transfers of pointer ownership, but is it considered really bad form to initialize a derived class object with a base class version if the data you need to copy is predominantly contained in the base class, but you need specific functionality that is only supported in the derived class? Thanks a lot.

  • 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-30T12:32:40+00:00Added an answer on May 30, 2026 at 12:32 pm

    With this design you get “sideways-conversion” in your class hierarchy, e.g.

    void foo(ItemExtension const&)
    
    class OtherItemExtension: public Item { /* ... */ };
    OtherItemExtenstion bar;
    
    foo(bar);
    

    Here the call to foo succeeds by creating a temporary ItemExtension from bar and passing that to foo. Most likely that is not what you want.

    Note that even if you make the constructor explicit, the following will still succeed:

    ItemExtension baz(bar);
    

    You most likely don’t want that, making it a bad idea to have that constructor.

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

Sidebar

Related Questions

I have an unusual problem. Let's consider such models (taken from django docs): class
Salute.. I have an unusual problem. Here in this table in MSDN library we
I have an unusual problem. I have a function, operation in this function can
I have an unusual problem (this is linked to Browser displays � instead of
I have encountered a slightly unusual problem. Consider the following code: class parser {
I have little unusual problem to solve. I need some hint or links to
I have an unusual problem with my views - after a while of using
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
i have an really unusual problem i've never had before. i've no .htaccess file

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.