Re: FixedSizeArray

Hi Peter,

Why two functions when

CPPUNIT_ASSERT (array.size() == 11);

works? The compiler will always be able to determine the object type and will know how to call the function. I could be missing something though…

I actually meant that the static function could be called with an object too:

CPPUNIT_ASSERT (array.arraySize() == 11);

Yes, I’m aware of this C++ “feature”. However, I’m used to create two separate functions (static and const) for these two reasons:

  • I think it’s not very well known behavior (especially among less experienced C++ programmers), so one could be confused that there is only a static function and call something like PeerInfo::size() or peerInfo.toByteArray().size() instead of peerInfo.size() when needed. But maybe I’m wrong and it’s known ;).
  • From what I’ve read, it’s not recommended way of calling static functions (for example, one of the best C++ writers in the Czech Republic says, that it leads to less well-arranged code).

On the other side, I’m not calling static functions within class member functions by explicitly specifying the class name.

Have a nice day,

Petr

Would you like to post a relpy?


This post is a reply to:
Re: FixedSizeArray
Hi Petr, I actually meant that the static function could be called with an object too: CPPUNIT_ASSERT (array.arraySize() == 11); Regards, Peter

Follow-ups:
Re: FixedSizeArray
Hi Petr, - I think it’s not very well known behavior (especially among less experienced C++ programmers), so one could be confused that there is only a static function and call (more...)