Giving a function implementation more than one name in c++

Let say I have a basic 2D vector class something like

class vector2
{
  int x, y;
}

these two values could be used to represent a position as well as a width and height. does C++ provide a away for me to impliment a function such as vector2::getXpos() and then also define vector2::getWidth() and have it use the same implementation.

I know that I could just make both of these function inline, but the compiler might decide to not inline these functions. so if getWidth just called getXpos you would end up with two function calls.

A more relistic example of what I would want to use this for is getLength() and erm... getSpan() (thinking of like a screen here for when you say 40" tv)

I would assume that this would be a simple case of something like a special function definition... I did find this page but this sounds like it is a C feature... and a bit of a hack to get working.

EDIT

I am not asking about the mechanics of inline functions... I basicaly want to do something functionally like

class MyClass
{
  void ActaullyDoStuff();
  public:
  void foo(){ActaullyDoStuff();}
  void bar(){ActuallyDoStuff();}
}

but where I can just write something like

class MyBetterClass
{
  public:
  void foo(){ /* BLOCK OF CODE */ }
  void bar(){ /* DO WHAT EVER foo() DOES */ }
}

I want bar() to be another way of just doing foo() so that the same functional code can have different, more appropriate names depending on the situation.

5
задан thecoshman 14 November 2010 в 15:35
поделиться