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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:47:34+00:00 2026-06-11T03:47:34+00:00

I just write a simple operator= in Widget,but when I operator= it ,it throws

  • 0

I just write a simple operator= in Widget,but when I operator= it ,it throws an Unhandled exception in vs2010.
I don`t see any wrong in these code. needs some help.

 class WidgetImpl
    {
        public:
            WidgetImpl ( int _a, int _b, int _c ) :
                a_ ( _a ), b_ ( _b ), c_ ( _c )
            {
            };
            //WidgetImpl& operator= ( const WidgetImpl& rhs ) {    //if I define this function,everything will be allright.

            //   if ( this == &rhs ) { return *this; }
            ////
            ////.... do something

            ////
            //return *this;
            // }

            int  a_, b_, c_;
            std::vector<double> vector_;
    };


    class Widget
    {
        public:
            Widget () : pImpl_ ( NULL ) {};
            Widget ( const Widget& rhs ) {};
            Widget& operator= ( const Widget& rhs ) 
            {
                if ( this == &rhs ) { return *this; }

                *pImpl_ = * ( rhs.pImpl_ );   
                return ( *this );
            }
            void SetImp ( WidgetImpl* _Impl )
            {
                this->pImpl_ = _Impl;
            }

            WidgetImpl* pImpl_;
    };

    int main ( int argc, char** argv )
    {
        Widget w;
        WidgetImpl* wimpl = new WidgetImpl ( 1, 2, 3 );
        w.SetImp ( wimpl );
        Widget w2;
        w2 = w;  //Unhandled exception throws here

        return 0;
    }

As you can see above.If I define operator= in class WidgetImpl . It seems everything is OK.. weird..

  • 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-11T03:47:35+00:00Added an answer on June 11, 2026 at 3:47 am

    Your w2‘s pImpl_ is null, so assigning to it will result in undefined behaviour (typically, a segmentation violation).

    In the code

                *pImpl_ = * ( rhs.pImpl_ );   
    

    the pImpl_ on the LHS is null.

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

Sidebar

Related Questions

I've just started with VB in VS2010 and attempting to write a simple console
how can I write just a simple disassembler for linux from scratches? Are there
How do you guys write comments on some simple code that you use just
I have a macro to write, quite simple. It just pulls numeric values from
Just wanted to write some recursion but can't check if the child is in
I just write an simple example to test boost::bind. I use it to instantiate
I just tried to write a simple C program on OSX Lion #include <stdio.h>
Lets say I want to write an AJAX chat box, just something simple, I
Well. I'm trying to write simple scheduler in ruby, just simple script which once
I just got this frame for a sudoku solver, but I don't understand the

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.