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()orpeerInfo.toByteArray().size()instead ofpeerInfo.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
