Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does the linked arrow operator (->) do here?

Status
Not open for further replies.

sedawk

Programmer
Feb 5, 2002
247
US
I am not familiar with the double arrow operator in the following code:

Start with a struct:
Code:
struct sc_curr_proc_info
{
     sc_process_b*  process_handle; 
     sc_curr_proc_info();   // remove initialize parameters
}

Then sc_get_curr_simcontext() is defined as
Code:
inline sc_simcontext*
sc_get_curr_simcontext()
{
    if( sc_curr_simcontext == 0 ) {
        sc_default_global_context = new sc_simcontext;
        sc_curr_simcontext = sc_default_global_context;
    }
    return sc_curr_simcontext;
}

followed by another related function
Code:
inline
sc_curr_proc_handle
sc_simcontext::get_curr_proc_info()
{
    return &m_curr_proc_info;
}

Finally, the question snippet on this double arrow operators
Code:
inline
sc_process_b*
sc_get_current_process_b()
{
    return sc_get_curr_simcontext()->get_curr_proc_info()->process_handle;
}

What do the two arrow operators do here? This is from SystemC's source code.

Thanks.
 
a->b is short for (*a).b

It dereferences a struct or class pointer and accesses a member variable or function in that struct or class.
 
Also watch out for smart-pointers. -> may be overridden. Check the operator definitions.

Note also that there is a ->* operator.
 
I can add something to my own question:

This is a "chain operator". The first arrow returns an object which can use the last method after the second arrow. See "C++ FAQ LITE
 
sc_get_curr_simcontext() returns a pointer to a sc_simcontext object, then get_curr_proc_info() returns a sc_curr_proc_info object, and process_handle is a member of that object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top