Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualNightCreature83

Posted 14 November 2012 - 03:04 AM

Using find is also not needed as you know which item you need to check, even if you get it working (I believe that if you use Strings, aItem is a struct and they are the first element declared in the struct it will work as intended), you will be tossing away processing (as you need to find the element in the array).

Actually his implementation will always work regardless of where the string is stored in the same struct as he is providing an == operator which find will call for the data type you give it.

Also another tip: instead of doing index++, try to use ++index. In this case it doesn't matter but it is a good habit to have, so when you only want to increment and decrement a variable by 1 ever and nothing else write ++var or --var. The reason behind this is that the ++operator or --operator(both pre and post increment or decrement) can be overloaded and do a lot of work that is unnecessary in that particular case.

#2NightCreature83

Posted 14 November 2012 - 03:03 AM

Using find is also not needed as you know which item you need to check, even if you get it working (I believe that if you use Strings, aItem is a struct and they are the first element declared in the struct it will work as intended), you will be tossing away processing (as you need to find the element in the array).

Actually his implementation will always work regardless of where the string is stored in the same struct as he is providing an == operator which find will call for the data type you give it.

Also another tip: instead of doing index++, try to use ++index. In this case it doesn't matter but it is a good habit to have, so when you only want to increment and decrement a variable by 1 ever and nothing else write ++var or --var. The reason behind this is that the ++operator (both pre and post increment or decrement can be overloaded and do a lot of work that is unnecessary in that particular case.

#1NightCreature83

Posted 14 November 2012 - 03:03 AM

Using find is also not needed as you know which item you need to check, even if you get it working (I believe that if you use Strings, aItem is a struct and they are the first element declared in the struct it will work as intended), you will be tossing away processing (as you need to find the element in the array).

Actually his implementation will always work regardless of where the string is stored in the same struct as he is providing an == operator which find will call for the data type you give it.

Also another tip: instead of doing index++, try to use ++index. In this case it doesn't matter but it is a good habit to have, so when you only want to increment and decrement)a variable by 1 ever and nothing else write ++var. The reason behind this is that the ++operator (both pre and post increment or decrement can be overloaded and do a lot of work that is unnecessary in that particular case.

PARTNERS