Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

It's hard to know where to start with this, but here are some things that may help you improve your code.

When seeking a review, provide full code

The posted code is just a fragment with a lot of pieces missing. For instance, all of the taste_box_x functions are missing and it's not really very obvious what they might be. To get a better review, post a better question.

Pass complex types reference rather than by value

For complex types such as std::vector, it's usually better to pass by reference rather than by value to avoid forcing each function call to make copies. If the passed object should not be modified by the routine, pass a const reference.

Use classes

Since this is C++, it would make sense to use classes. For example, one could imagine that there is a base class box from which each of the box types might be derived. User taste preference could be an std::unordered_set in which each fruit type is the key and the value would be that user's taste weighting value. Fruits might be an enum class, etc.

Don't abuse using namespace std

Putting using namespace std at the top of every program is a bad habit a bad habit that you'd do well to avoid.

It's hard to know where to start with this, but here are some things that may help you improve your code.

When seeking a review, provide full code

The posted code is just a fragment with a lot of pieces missing. For instance, all of the taste_box_x functions are missing and it's not really very obvious what they might be. To get a better review, post a better question.

Pass complex types reference rather than by value

For complex types such as std::vector, it's usually better to pass by reference rather than by value to avoid forcing each function call to make copies. If the passed object should not be modified by the routine, pass a const reference.

Use classes

Since this is C++, it would make sense to use classes. For example, one could imagine that there is a base class box from which each of the box types might be derived. User taste preference could be an std::unordered_set in which each fruit type is the key and the value would be that user's taste weighting value. Fruits might be an enum class, etc.

Don't abuse using namespace std

Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid.

It's hard to know where to start with this, but here are some things that may help you improve your code.

When seeking a review, provide full code

The posted code is just a fragment with a lot of pieces missing. For instance, all of the taste_box_x functions are missing and it's not really very obvious what they might be. To get a better review, post a better question.

Pass complex types reference rather than by value

For complex types such as std::vector, it's usually better to pass by reference rather than by value to avoid forcing each function call to make copies. If the passed object should not be modified by the routine, pass a const reference.

Use classes

Since this is C++, it would make sense to use classes. For example, one could imagine that there is a base class box from which each of the box types might be derived. User taste preference could be an std::unordered_set in which each fruit type is the key and the value would be that user's taste weighting value. Fruits might be an enum class, etc.

Don't abuse using namespace std

Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid.

Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

It's hard to know where to start with this, but here are some things that may help you improve your code.

When seeking a review, provide full code

The posted code is just a fragment with a lot of pieces missing. For instance, all of the taste_box_x functions are missing and it's not really very obvious what they might be. To get a better review, post a better question.

Pass complex types reference rather than by value

For complex types such as std::vector, it's usually better to pass by reference rather than by value to avoid forcing each function call to make copies. If the passed object should not be modified by the routine, pass a const reference.

Use classes

Since this is C++, it would make sense to use classes. For example, one could imagine that there is a base class box from which each of the box types might be derived. User taste preference could be an std::unordered_set in which each fruit type is the key and the value would be that user's taste weighting value. Fruits might be an enum class, etc.

Don't abuse using namespace std

Putting using namespace std at the top of every program is a bad habit that you'd do well to avoid.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /