Results 1 to 5 of 5

Thread: silly array element counter..

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    US
    Posts
    173
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android
    Thanks
    16
    Thanked 5 Times in 5 Posts

    Default Re: silly array element counter..

    Stroustrup recommends not using arrays. Many coding standards insist on never using arrays.

    See "What's wrong with arrays?" at
    http://public.research.att.com/~bs/bs_faq2.html

  2. #2
    Join Date
    Mar 2006
    Posts
    22
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: silly array element counter..

    Unless your array is NULL terminated, you have no way of finding out. This is why you often see array length as argument to array functions.

  3. #3
    Join Date
    Feb 2006
    Posts
    21
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows
    Thanks
    4
    Thanked 1 Time in 1 Post

    Thumbs up Re: silly array element counter..

    It may be nice to not impose a particular type of container (like std::vector) on the callers of the int MyClass::MyString method. Sometimes, I like to make these types of methods templatized on an iterator type like this:
    Qt Code:
    1. template< class IteratorType >
    2. int MyClass::MyString(const IteratorType &iterBegin, const IteratorType &iterEnd)
    3. {
    4. // Get a count of items passed in.
    5. const size_t nNumItems = iterEnd-iterBegin;
    6.  
    7. // Iterate over the input
    8. IteratorType iter;
    9. for(iter = iterBegin; iter != iterEnd; ++iter)
    10. {
    11. // Do something here.
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Ben.Hines; 3rd March 2006 at 16:02.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.