GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 09-Sep-2007, 21:30
Blase Blase is offline
Junior Member
 
Join Date: Jun 2006
Posts: 36
Blase has a little shameless behaviour in the past

Converting objects of classes


Hi,

"Explain why it is essential that a class that dynamically allocate memory in the constructor also needs a properly written copy constructor and assignment operator."

Is the above question related to memory leaks? How would we know if we have 'improperly' written the copy constructor and assignment operator? What are the pre-emptive measures?

"What are the two ways of achieving automatic type conversion from an object of class X into an object of class Y?"
  #2  
Old 11-Sep-2007, 06:50
davis
 
Posts: n/a

Re: Converting objects of classes


Quote:
Originally Posted by Blase
Hi,

"Explain why it is essential that a class that dynamically allocate memory in the constructor also needs a properly written copy constructor and assignment operator."

Is the above question related to memory leaks? How would we know if we have 'improperly' written the copy constructor and assignment operator? What are the pre-emptive measures?

See: www.gidforums.com

...for more details.


Quote:
Originally Posted by Blase
"What are the two ways of achieving automatic type conversion from an object of class X into an object of class Y?"

Using a derived where a base is required and assignment/copy of a base from a derived?

CPP / C++ / C Code:
#include <iostream>

using namespace std;

class X
{
public:
    void what()
    {
        cout << "X" << endl;
    }
};

class Y : public X
{
public:
    void what()
    {
        cout << "Y" << endl;
    }
};

void bogus( X& x )
{
    x.what();
}

int main()
{
    X x;
    Y y;
    bogus( y );
    x = y;
    x.what();
}

Output:

Code:
X X


:davis:
 
 

Recent GIDBlogMeeting the local Iraqis by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem accessing functions in inherited classes jj90 C++ Forum 4 14-May-2007 14:12
Beginner working with classes Timothy_Bennett C++ Forum 14 05-Apr-2007 22:22
a quick question about using classes, objects and their properties... abakws MySQL / PHP Forum 1 20-Nov-2006 09:31

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:30.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.