Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  • No need for an empty constructor in C++11:

    Array()
    {
    }
    

    You can just use a default constructor:

     Array() = default;
    
  • It's a little confusing to have multiple public/private sections. Here, you can just put all the public code under the same keyword.

  • You could make your structure more useful by providing iterators. This will, for instance, allow you to use range based for-loops instead of plain ones for iterating through this structure.

  • You don't need std::endl if you just need newlines. Just output "\n" instead for this. More info about this can be found here here.

  • It's unnecessary to have your own return 0 at the end of main() in C++. The compiler will provide this return for you.

  • No need for an empty constructor in C++11:

    Array()
    {
    }
    

    You can just use a default constructor:

     Array() = default;
    
  • It's a little confusing to have multiple public/private sections. Here, you can just put all the public code under the same keyword.

  • You could make your structure more useful by providing iterators. This will, for instance, allow you to use range based for-loops instead of plain ones for iterating through this structure.

  • You don't need std::endl if you just need newlines. Just output "\n" instead for this. More info about this can be found here.

  • It's unnecessary to have your own return 0 at the end of main() in C++. The compiler will provide this return for you.

  • No need for an empty constructor in C++11:

    Array()
    {
    }
    

    You can just use a default constructor:

     Array() = default;
    
  • It's a little confusing to have multiple public/private sections. Here, you can just put all the public code under the same keyword.

  • You could make your structure more useful by providing iterators. This will, for instance, allow you to use range based for-loops instead of plain ones for iterating through this structure.

  • You don't need std::endl if you just need newlines. Just output "\n" instead for this. More info about this can be found here.

  • It's unnecessary to have your own return 0 at the end of main() in C++. The compiler will provide this return for you.

Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
  • No need for an empty constructor in C++11:

    Array()
    {
    }
    

    You can just use a default constructor:

     Array() = default;
    
  • It's a little confusing to have multiple public/private sections. Here, you can just put all the public code under the same keyword.

  • You could make your structure more useful by providing iterators. This will, for instance, allow you to use range based for-loops instead of plain ones for iterating through this structure.

  • You don't need std::endl if you just need newlines. Just output "\n" instead for this. More info about this can be found here.

  • It's unnecessary to have your own return 0 at the end of main() in C++. The compiler will provide this return for you.

lang-cpp

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