954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

please help - whats happening here in the code snippet given??

Can anyone help me to let me know whats happening in the below code when ,

data=cs.data;


happens
as FYI,
data is an empty list created of type std::list
and the constructor definition given below is a copy constructor

LDAPControlSet::LDAPControlSet(const LDAPControlSet& cs){
    DEBUG(LDAP_DEBUG_CONSTRUCT,"LDAPControlSet::LDAPControlSet(&)" << endl);
    data=cs.data;
}


thanks in advance

ermithun
Light Poster
29 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

Copy constructor is invoke when you initialize an object with another.
In this case, it will be invoked something like this:

LDAPControlSet a;
//do something with 'a'.
LDAPControlSet b=a;//copy constructor invoked with 'a' as the argument
LDAPControlSet c;
c=b;// copy constructor *not* invoked but initialization operator invoked
LDAPControlSet d(a);//explicit invocation of the copy constructor with 'a'  as argument

When this copy constructor is called, it simply copies the content of the std::list cs::data to its own std::list data.
In the above example, a is passed as parameter to the copy constructor's parameter cs.
cs.data is the std::list of that argument
and data is the std::list of the own object.

siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

THanks Siddhant.

one more help,
actly i m trying to reproduce the segmentation fault in my code, please let me know whether the below code is capable of giving rise to that error or not or if not what should i do to this code.

int main()
{
        LDAPControlSet *cset = new LDAPControlSet();
        LDAPControlSet *cs = new LDAPControlSet("1");

        delete cs;
        data=cset.data;

        data=cs.data;

        cout<<"I am here";
        return 0;
}
ermithun
Light Poster
29 posts since Jun 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You