Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Copy Constructor

This is a discussion on Copy Constructor within the C and C++ forums, part of the Software Development category; While we create a copy constructor Is this code coreect or wrong? class a { public: a(a &b) {} }...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 12-10-2007
Junior Member
 
Join Date: Dec 2007
Location: Bangalore
Posts: 3
Thanks: 1
Thanked 1 Time in 1 Post
manoj200724 is on a distinguished road
Copy Constructor

While we create a copy constructor Is this code coreect or wrong?
class a
{
public:
a(a &b)
{}
}
Reply With Quote
The Following User Says Thank You to manoj200724 For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 12-11-2007
Junior Member
 
Join Date: Dec 2007
Location: India
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mandeep422 is on a distinguished road
Re: Copy Constructor

It should be like ::

class a
{
public:
a(const a &b)
{}
}
Reply With Quote
  #3 (permalink)  
Old 12-12-2007
Junior Member
 
Join Date: Dec 2007
Location: banagalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vikram_lok is on a distinguished road
Post Re: Copy Constructor

Quote:
Originally Posted by manoj200724 View Post
While we create a copy constructor Is this code coreect or wrong?
class a
{
public:
a(a &b)
{}
}

This is absolutely correct. const is required to prevent the passing object being changed by copy constructor code.

Last edited by vikram_lok; 12-12-2007 at 02:50 AM.
Reply With Quote
  #4 (permalink)  
Old 12-19-2007
Contributing Member
 
Join Date: Nov 2007
Location: bangalore
Posts: 54
Thanks: 6
Thanked 6 Times in 4 Posts
rahulvegi is on a distinguished road
Re: Copy Constructor

i think its working. i will say tomorrow how it works
Reply With Quote
  #5 (permalink)  
Old 05-06-2008
Junior Member
 
Join Date: May 2008
Location: India
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
YogitaSabnis is on a distinguished road
Re: Copy Constructor

Copy constructor can be like this

B(const B &b)
{
//initialization
}
Reply With Quote
  #6 (permalink)  
Old 05-22-2008
Junior Member
 
Join Date: May 2008
Location: new delhi
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
gogia_rajat is on a distinguished road
Re: Copy Constructor

ur code is absolutely correct
Reply With Quote
  #7 (permalink)  
Old 05-29-2008
Junior Member
 
Join Date: May 2008
Location: india
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
lipune is on a distinguished road
Re: Copy Constructor

that code is correct,but if u create a constant object then dt code is not correct,u have to write const classname&,like dt.ok,,,,,,,if u do not write const object then dt code is ok.
Reply With Quote
  #8 (permalink)  
Old 06-15-2008
Junior Member
 
Join Date: Jun 2008
Location: Bangalore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
sen49 is on a distinguished road
Re: Copy Constructor

What ever u have written that is absolutely correct...
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
constructor emb.mallik C and C++ 1 03-02-2009 04:50 PM
Class copy constructor and assignment operator Geek_Guest C and C++ 1 12-21-2007 05:49 AM
Constructor and init() pramod.kuber Java 3 11-04-2007 02:42 AM
why i am getting an error while calling a constructor from another constructor raj_java_j2ee Java 4 07-22-2007 03:39 AM
Silent Copy - copy your files with the convenience! JobHelper Geeks Lounge 0 04-05-2007 04:40 AM


All times are GMT -4. The time now is 06:33 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved