Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: A question about varaibles that I should give to functions in C++

Author: Dann Corbit

Date: 10:50:18 08/02/04

Go up one level in this thread


On August 02, 2004 at 00:17:10, Hristo wrote:

>On August 01, 2004 at 22:21:26, James Swafford wrote:
>
>>On August 01, 2004 at 05:52:03, Hristo wrote:
>>
>>>On August 01, 2004 at 01:07:10, Uri Blass wrote:
>>>
>>>>My code until today used a lot of global varaibles and I decided based on advice
>>>>of Dann Corbit to use a class for time management.
>>>>
>>>>I have a many varaibles in class for time management and
>>>>I hesitate which parameters to give to the functions.
>>>>
>>>>I will give an example:
>>>>
>>>>I want to have a procedure to update the remaining number of moves to the time
>>>>control in the beginning of every search(this varaible is used for other
>>>>varaibles like the target time.
>>>>
>>>>The procedure is using the following varaibles:
>>>>1)num_moves_1(number of moves in the first time control)
>>>>2)num_moves_2(number of moves in the second time control)
>>>>3)num_moves_3(number of moves in the third time control)
>>>>4)hply(history ply of the game)
>>>
>>>
>>>Uri,
>>>if you should provide accessor functions for your class attributes (variables).
>>>In other words, it is a common practice to expose your variables through
>>>independent functions (set/get).
>>>
>>>For instance:
>>>class UrisTime{
>>>public:
>>>  UrisTime(){}
>>>  ~UrisTime(){}
>>>
>>>  int getMoves1(void) const { return num_moves_1;}
>>>  void setMoves1(int i) { num_moves_1 = i;}
>>>
>>>  int getMoves2(void) const { return num_moves_2;}
>>>  void setMoves2(int i) { num_moves_2 = i;}
>>>
>>>  int getMoves3(void) const { return num_moves_3;}
>>>  void setMoves3(int i) { num_moves_3 = i;}
>>>
>>>  int getHply(void) const { return hply;}
>>>  void setHply(int i) { hply = i;}
>>>
>>>protected:
>>>  int num_moves_1;
>>>  int num_moves_2;
>>>  int num_moves_3;
>>>  int hply;
>>>};
>>>
>>>
>>>You can also inline the functions if you think that they would be called very
>>>often: just add inline in front of the functions.
>>>
>>>  inline int getMoves1(void) const { return num_moves_1;}
>>>  inline void setMoves1(int i) { num_moves_1 = i;}
>>
>>You don't need to explicitely state 'inlined' if the
>>function is in the class definition-- it is implicit.
>
>It is just a hint to the compiler, at any rate, :-)
>The compiler doesn't have to obey it anyway.
>But as you said, it "doesn't hurt."!

It may also create static versions for each file, as an alternative.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.