ok...may be i forgot , can you please tell me correct code for the copy
constructor..?

On Sun, Aug 21, 2011 at 1:31 PM, JAIDEV YADAV <jaid...@gmail.com> wrote:

> dude u haven't used copy constructor properly .. check it out again ... you
> are not copying actually ... thats it ...
>
> On Sun, Aug 21, 2011 at 12:53 PM, Abhishek Yadav <
> algowithabhis...@gmail.com> wrote:
>
>> Check this code: the thing i couldn't understand is when the object is
>> being returned neither the copy constructor is being called nor the
>>  assignment operator overload is called....then how the object is being
>> copied into b. i don't think default copy constructor should be called if i
>> have made our own copy constructor....???
>> #include<iostream>
>> using namespace std;
>> #include<conio.h>
>>
>> class X
>> {
>>       public:
>>   int num;
>>     X(int a)
>>     {
>> num=a;
>>              cout<<"\n constructor";
>>     }
>>
>>     X(const X& t)
>>  {
>> this->num=t.num;
>> cout<<"\nCopy ";
>>  }
>>
>> X operator=(const X& t)
>> {
>>  this->num =t.num;
>> cout<<"\n Assigment   ";
>> return t;
>>  }
>>
>>     X fun()
>>     {
>>            cout<<"\nin fun";
>>            return X(7);
>>      }
>>
>> ~X()
>> {
>> cout<<"\ndestruct ";
>>  }
>>
>> };
>>
>> int main()
>> {
>> {
>>     X a(1);
>>    X b=a.fun();
>>    cout<<"\n\n"<<b.num;
>> }
>> getch();
>> }
>>
>>
>> On Sun, Aug 21, 2011 at 12:33 PM, Abhishek Yadav <
>> algowithabhis...@gmail.com> wrote:
>>
>>> The code is correct..return X will make a temporary object and for that a
>>> constructor and corresponding destructor will be called and that  object is
>>> returned.
>>>
>>> On Sun, Aug 21, 2011 at 12:24 PM, Puneet Chawla <
>>> puneetchawla...@gmail.com> wrote:
>>>
>>>> It will show error
>>>>
>>>> On Sun, Aug 21, 2011 at 12:21 PM, Sanjay Rajpal <srn...@gmail.com>wrote:
>>>>
>>>>> I think it will not be an error.
>>>>>
>>>>> This is because X() will create a temporary object, and when the
>>>>> object is returned in the function calling it, then default copy
>>>>> constructor will do bitwise copy of data members in the calling
>>>>> function.
>>>>>
>>>>> Correct me if m wrong.
>>>>>
>>>>> On 8/20/11, sachin sabbarwal <algowithsac...@gmail.com> wrote:
>>>>> > class X()
>>>>> > {
>>>>> >
>>>>> > X()
>>>>> > {
>>>>> > }
>>>>> >
>>>>> >
>>>>> >
>>>>> > X fun()
>>>>> > {
>>>>> > return X();      //error or what?? because constructor never returns
>>>>> > anything so what this return statement will receive after executing
>>>>> x() and
>>>>> > what it will return??
>>>>> > }
>>>>> >
>>>>> >
>>>>> > };
>>>>> >
>>>>> > --
>>>>> > You received this message because you are subscribed to the Google
>>>>> Groups
>>>>> > "Algorithm Geeks" group.
>>>>> > To post to this group, send email to algogeeks@googlegroups.com.
>>>>> > To unsubscribe from this group, send email to
>>>>> > algogeeks+unsubscr...@googlegroups.com.
>>>>> > For more options, visit this group at
>>>>> > http://groups.google.com/group/algogeeks?hl=en.
>>>>> >
>>>>> >
>>>>>
>>>>>
>>>>> --
>>>>> Sanju
>>>>> :)
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Algorithm Geeks" group.
>>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>>> To unsubscribe from this group, send email to
>>>>> algogeeks+unsubscr...@googlegroups.com.
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> With regards
>>>>   ............
>>>> Puneet Chawla
>>>> Computer Engineering Student
>>>> NIT Kurukshetra
>>>>
>>>>  --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to algogeeks@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> algogeeks+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> JaiDev Yadav
> (National Yoga Champion)
> Computer Engg. Dept.
> National Institute of Technology
> Kurukshetra,Haryana
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to