Skip to main content
GameDev.net gamedev.net
๐Ÿ”’ Locked

using method return value as default argument

Started by moussen15 Aug 6, 2006 at 12:35 PM 0 replies 600+ views
Original Post
moussen15
moussen15
This must be possible, but I can't figure out how. I was thinking something like this:

class cMyClass
{
      public:
              int  increase( int x, int amount = getStandardIncreaseAmount() );
              int  getStandardIncreaseAmount();
};

; But my compiler complains about not being able to call getStandardIncreaseAmount() without an object (adding "this->" doesn't solve the problem because "it can't be used in this context" or something. Does anybody know how to do this?
SiCrane
SiCrane
Assuming C++ (or another language with function overloading), you can add an overload for increase:
  int increase(int x) { return increasee(x, getStandardIncreaseAmount()); }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.