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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:18:37+00:00 2026-05-25T20:18:37+00:00

As you know compiler defines default constructor, copy constructor, assignment operator and destructor for

  • 0

As you know compiler defines default constructor, copy constructor, assignment operator and destructor for POD structures if it weren’t defined manually. Usually (or maybe should I say always) it’s a bit copy operation. So I’ve decided to inherit my class from Win structure BITMAP to provide memory allocation in constructor and freeing in destructor. I haven’t used composition ‘coz I want to allow using it with some WinAPI functions. Here is a some piece of code:

class CPreviewFrame : public BITMAP
{
public:
   CPreviewFrame( );
   CPreviewFrame( std::size_t width, std::size_t height, UCHAR bytesPerPixel = 3 );
   CPreviewFrame( const CPreviewFrame& frame );

   ~CPreviewFrame( );
   .....
};

And copy constructor is defined something like that:

CPreviewFrame::CPreviewFrame( const CPreviewFrame& frame ):
   BITMAP( static_cast<BITMAP>(frame) ), //question is here
   m_bufferSize( frame.m_bufferSize )
{
   bmBits = new uint8_t[ m_bufferSize ];
   memcpy( bmBits, frame.bmBits, m_bufferSize );
}

So my question is: Is it proper way to call compiler defined copy constructor from inherited structure or should I copy all fields manually in constructor body? Both variants look somewhat strange for me because POD structs can’t have constructors despite compiler defines them. How can you call constructor for POD data type if it doesn’t exist by definition?

P.S. Code mentioned above compiles well on VS2010.

P.P.S. There is related question to this theme posted by me here.

  • 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-25T20:18:38+00:00Added an answer on May 25, 2026 at 8:18 pm

    BITMAP(frame) will do the trick with no cast needed as the compiler will know the type of the parent and be able to implicitly convert the argument. Note that if you want to use a cast to explicit show what you’re doing, cast as a reference type: BITMAP( static_cast<const BITMAP&>(frame) ),

    Also, seriously consider this inheritance. Sometime a year or two from now someone’s going to delete one of your CPreviewFrame objects as a BITMAP. Best case they leak memory, worst case you spend days or weeks debugging why the app isn’t working right. Composition (with an appropriate interface that may call WinAPI function behinds the scene) isn’t typically that complicated to implement and it will more accurately and correctly model your problem here.

    Alternately you could use composition and just provide a getter to the bitmap portion (as suggested in a comment). This exposes implementation details of your class but might make it easier to code to the Win API in the short term.

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

Sidebar

Related Questions

Does anyone know the full list of C# compiler number literal modifiers? By default
We know that compiler generates some member functions for user-defined class if that member
The C# compiler requires that whenever a custom type defines operator == , it
I know compiler may or may not perform inline expansion of a function whether
Anyone know this compiler feature? It seems GCC support that. How does it work?
For instance, does the compiler know to translate string s = test + this
I know that the compiler will sometimes initialize memory with certain patterns such as
The compiler doesn't know where stat.h is? Error: c:\Projects\ADC_HCI\mongoose.c(745) : error C2079: 'st' uses
I know there is a standard behind all C compiler implementations, so there should
Do you know how strong VLIW architectures support exists in GCC compiler infrastructure? I

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.