It is currently Tue Dec 12, 2017 7:19 am

All times are UTC - 5 hours




 Page 1 of 1 [ 3 posts ] 
Author Message
 Post subject: C++ VMK 9 - Classes in C++
PostPosted: Mon Sep 10, 2007 6:05 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
VMK9A compares the differences between a struct and a class. I also go onto show how to use public and private functions and variables within a class and how to use a class constructor.

VMK9B demonstrates how to use static members and static functions within a class.

VMK9C describes class inheritance and how to use public, private and protected functions and variables.

VMK9D shows you why you need to create a copy constructor when working with dynamic memory inside of a class.


Last edited by Marek on Thu Dec 27, 2007 10:09 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 5:46 am 

Joined: Sun Dec 02, 2007 3:24 am
Posts: 13
Location: Galati
I have a question ...

Let's say that I have a class and in the main()
function I do something like this :

1 : class_name var2;
2 : class_name var1 = var2;


I have declared and defined a copy constructor for this class.

On line 2 when var1 is created , besides the copy constructor , is the constructor of the class called ???

Thanks In Advance !!!


Last edited by Arthy on Fri Dec 28, 2007 9:43 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject:
PostPosted: Thu Dec 27, 2007 10:24 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
On line 2 of your code, the operator= function is NOT called. Only the copy constructor will be called : ie class_name ( const class_name &c).

If you don't have this constructor defined, then the default constructor class_name() will be called, which is a bad thing if you have dynamic memory allocated in your class.


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron