# Include <New. h> <br/> # include <iostream> <br/> using namespace STD; <br/> # include <stdlib. h> <br/> # include <time. h> <br/> # include <stdio. h> <br/> class d_hello; <br/>/** <br/> * probematch Message format in the same ed data soap: body. <br/> */<br/> class d_probematch <br/> {<br/> Public: <br/> d_probematch () <br/>{< br/> memset (m_d_types, 0,500); <br/> memset (m_d_scopes,); <br/> memset (m_d_xaddrs); <Br/> memset (m_d_metadataversion, 0, 10); <br/>}< br/> d_probematch (const d_probematch & probeobj) <br/>{< br/> strcpy (m_d_types, probeobj. m_d_types); <br/> strcpy (m_d_scopes, probeobj. m_d_scopes); <br/> strcpy (m_d_xaddrs, probeobj. m_d_xaddrs); <br/> strcpy (m_d_metadataversion, probeobj. m_d_metadataversion); <br/>}< br/> // d_probematch (const d_hello & helloobj) <br/>/{ <br/> // strcpy (m_d_types, helloobj. m_d _ Types); <br/> // strcpy (m_d_scopes, helloobj. m_d_scopes); <br/> // strcpy (m_d_xaddrs, helloobj. m_d_xaddrs); <br/> // strcpy (m_d_metadataversion, helloobj. m_d_metadataversion); <br/> //} <br/> d_probematch & operator = (const d_probematch & probeobj) <br/>{< br/> strcpy (m_d_types, probeobj. m_d_types); <br/> strcpy (m_d_scopes, probeobj. m_d_scopes); <br/> strcpy (m_d_xaddrs, probeobj. m_d_xaddrs); <br/> strcpy (m_d_meta Dataversion, probeobj. m_d_metadataversion); <br/> return * This; <br/>}< br/> // d_probematch & operator = (const d_hello & helloobj) <br/> // {<br/> // strcpy (m_d_types, helloobj. m_d_types); <br/> // strcpy (m_d_scopes, helloobj. m_d_scopes); <br/> // strcpy (m_d_xaddrs, helloobj. m_d_xaddrs); <br/> // strcpy (m_d_metadataversion, helloobj. m_d_metadataversion); <br/> // return * This; <br/>/} <br/> virtual ~ D_probematch () {}</P> <p> char m_d_types [50]; <br/> char m_d_scopes [500]; <br/> char m_d_xaddrs [50]; <br/> char m_d_metadataversion [10]; <br/>}; <br/>/** <br/> * Hello Message format. <br/> */<br/> class d_hello <br/> {<br/> Public: <br/> d_hello () <br/>{< br/> memset (m_d_types, 0,500); <br/> memset (m_d_scopes,); <br/> memset (m_d_xaddrs ); <br/> memset (m_d_metadataversion, 0, 10); <br/>}< br/> virtual ~ D_hello () {}< br/> d_hello (const d_hello & helloobj) <br/>{< br/> strcpy (m_d_types, helloobj. m_d_types); <br/> strcpy (m_d_scopes, helloobj. m_d_scopes); <br/> strcpy (m_d_xaddrs, helloobj. m_d_xaddrs); <br/> strcpy (m_d_metadataversion, helloobj. m_d_metadataversion); <br/>}</P> <p> operator d_probematch () <br/>{< br/> d_probematch probe; <br/> strcpy (probe. m_d_types, m_d_types); <br/> strcpy (probe. m_d_scopes, m_d_scopes); <br/> strcpy (probe. m_d_xaddrs, m_d_xaddrs); <br/> strcpy (probe. m_d_metadataversion, m_d_metadataversion); <br/> return probe; <br/>}< br/> // attributes <br/> char m_d_types [50]; <br/> char m_d_scopes [500]; <br/> char m_d_xaddrs [50]; <br/> char m_d_metadataversion [10]; <br/> }; <br/> void main () <br/> {<br/> d_hello hello; <br/> strcpy (hello. m_d_metadataversion, "Version1"); <br/> strcpy (hello. m_d_scopes, "Scopes"); <br/> strcpy (hello. m_d_types, "types"); <br/> strcpy (hello. m_d_xaddrs, "Address"); <br/> d_probematch probe = Hello; <br/> printf ("% s/n", probe. m_d_scopes); <br/> getchar (); <br/>}
Add a breakpoint in operator d_probematch and d_probematch (const d_probematch & probeobj,
You will find that the operator d_probematch () function is called first, and then the copy structure is called (the first is returned in operator d_probematch
The second time is d_probematch probe = Hello; initialize the probe object ).
If you modify the code in main as follows:
D_probematch probe; <br/> probe = Hello;
After the copy construction is called for the first time, the second call is d_probematch & operator = (const d_probematch & probeobj)
Value assignment.
Of course, to improve efficiency, you can directly call d_probematch (const d_hello & helloobj), and change the class's life sequence.