Can I have one member function with two names? Like an Alias?

T

Tom

class CBlah
{
void MemberFun1( int x )
{ ... }
void MemberFun2( int x )
{ MemberFun1( x ); }
};

This doesn't look very efficient to me. Or might the compiler optimize MemberFun2 away? Or is there a better way to do this?

Thanks,
Tom.
 
M

Michiel Salters

Tom said:
class CBlah
{
void MemberFun1( int x )
{ ... }
void MemberFun2( int x )
{ MemberFun1( x ); }
};

This doesn't look very efficient to me. Or might the compiler optimize
MemberFun2 away? Or is there a better way to do this?

By writing the code within the class, you instruct the compiler to
"inline" the code for MemberFun1. Given its complexity, this is
likely to succeed. In debug mode, this often will be ignored though,
so you can fllow the code through MemberFun2

From an interface viewpoint, the second function doesn't add value
- although a real-world example might, with e.g. arguments
exchanged.

Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top