Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Copy Constructor Question
New Posts  All Forums:Forum Nav:

Copy Constructor Question

post #1 of 5
Thread Starter 
I did an excercise in my book and was learning Destructors, and copy constructors, And was just wondering (since it didnt say), What makes the Copy Constructor prototype unique to the Constructor prototype, Like i know they ARE different, But how is the prototype and definition different because they are written exactly the same? For example, When you create and instance of a class, How does it know wether to call the Constructor, Or the Copy Constructor since they are written the same.

I hope you know what im trying to ask, Also im writing in C++.

Android 16
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 2.8GHz Gigabyte P55A-UD3 Asus 512MB en9400 GT Silent 4GB 1600MHz Mushkin Radioactive DDR3 6-8-6-24 
Hard DriveOSMonitorKeyboard
140GB Seagate Barracuda (I think) Windows 7 Ultimate 64-Bit 24" LG Flatron W2452V LCD Generic Optima 
PowerCaseMouseMouse Pad
Silverstone Strider 500w NZXT Guardian 921 Generic Logitech laser mouse Razer Goliathus 
  hide details  
Reply
Android 16
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 2.8GHz Gigabyte P55A-UD3 Asus 512MB en9400 GT Silent 4GB 1600MHz Mushkin Radioactive DDR3 6-8-6-24 
Hard DriveOSMonitorKeyboard
140GB Seagate Barracuda (I think) Windows 7 Ultimate 64-Bit 24" LG Flatron W2452V LCD Generic Optima 
PowerCaseMouseMouse Pad
Silverstone Strider 500w NZXT Guardian 921 Generic Logitech laser mouse Razer Goliathus 
  hide details  
Reply
post #2 of 5
http://en.wikipedia.org/wiki/Copy_constructor
this might help.
Pepe Silvia
(13 items)
 
  
CPUMotherboardGraphicsRAM
255 @ 4 Ghz MSI 870-C45 GT 520 @ 1Ghz Crucial Rendition 4GB DDR3 
Hard DriveOSMonitorPower
Hitachi 1TB Win 7 19" 420W 
  hide details  
Reply
Pepe Silvia
(13 items)
 
  
CPUMotherboardGraphicsRAM
255 @ 4 Ghz MSI 870-C45 GT 520 @ 1Ghz Crucial Rendition 4GB DDR3 
Hard DriveOSMonitorPower
Hitachi 1TB Win 7 19" 420W 
  hide details  
Reply
post #3 of 5
if i understand your question correctly, the program knows to call the copy constructor and not the regular constructor based on the parameters you pass it. the copy constructor is called when you pass a constant reference to an object.

here's an example of a class that has both default and copy constructors.
http://www.cplusplus.com/forum/general/2666/
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
Fractal Design
(15 items)
 
775 4 life
(15 items)
 
 
CPUMotherboardGraphicsRAM
Intel i7 2600K Biostar TP67XE NVidia GTX 570 Crucial Ballistix 
Hard DriveHard DriveCoolingOS
Crucial C300 RealSSD SDD Samsung F4 2TB Noctua NH-D14 Windows 7 Professional x64 
MonitorMonitorKeyboardPower
Asus VH202T 20'' 1600x900 Acer P244W 24" 1920 x 1080 Apple Keyboard with Numeric Keypad SeaSonic M12II 620W 
CaseMouseAudio
Fractal Design Define XL Titanium Grey Razor Abyssus Creative Sound Blaster X-FI Xtreme Gamer 
CPUMotherboardGraphicsRAM
Intel X3350 3.2Ghz @ 1.25v Gigabyte-GA-P35-DS3L (rev 2) XFX 4870 1GB 4GB OCZ Reaper PC2-6400 
RAMHard DriveHard DriveOptical Drive
2GB Corsair XMS2 PC2-6400 Crucial C300 64GB SSD 2TB Samsung Spinpoint F4 Sony Super Multi 
OSMonitorPowerCase
Windows 7 Professional x64 SP1 Asus VH202T 20'' 1600x900 SeaSonic M12II 620W Cooler Master Centurion 5 
Mouse
Razor Abyssus 
CPUMotherboardGraphicsRAM
Core i5-520M Lenovo 2522BF3 NVIDIA® Quadro® NVS3100M  Ramaxel Technology 4Gb DDR3 
Hard DriveOptical DriveOSMonitor
Samsung SSD 128GB 1.8" Micro SATA  hl-dt-st dvdram gu10n Windows 7 Enterprise (64-bit) 14.1" WXGA (1280x800) display, anti-glare, LED ... 
Power
9-cell plus Slice battery 
  hide details  
Reply
post #4 of 5
Thread Starter 
AH, ofcourse, Because you would always have to pass a reference to the object. Thanks.
Android 16
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 2.8GHz Gigabyte P55A-UD3 Asus 512MB en9400 GT Silent 4GB 1600MHz Mushkin Radioactive DDR3 6-8-6-24 
Hard DriveOSMonitorKeyboard
140GB Seagate Barracuda (I think) Windows 7 Ultimate 64-Bit 24" LG Flatron W2452V LCD Generic Optima 
PowerCaseMouseMouse Pad
Silverstone Strider 500w NZXT Guardian 921 Generic Logitech laser mouse Razer Goliathus 
  hide details  
Reply
Android 16
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 760 @ 2.8GHz Gigabyte P55A-UD3 Asus 512MB en9400 GT Silent 4GB 1600MHz Mushkin Radioactive DDR3 6-8-6-24 
Hard DriveOSMonitorKeyboard
140GB Seagate Barracuda (I think) Windows 7 Ultimate 64-Bit 24" LG Flatron W2452V LCD Generic Optima 
PowerCaseMouseMouse Pad
Silverstone Strider 500w NZXT Guardian 921 Generic Logitech laser mouse Razer Goliathus 
  hide details  
Reply
post #5 of 5
Quote:
Originally Posted by kungfuelmo View Post
AH, ofcourse, Because you would always have to pass a reference to the object. Thanks.
See:
http://en.wikipedia.org/wiki/Function_overloading
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Copy Constructor Question