Hot answers tagged

3

Avoid using namespace std; If you are coding professionally you probably should get out of the habit of using the using namespace std; statement. The code will more clearly define where cout and other identifiers are coming from (std::cin, std::cout). As you start using namespaces in your code it is better to identify where each function comes from because ...


2

Quite a bit of code to look at. This is not a complete review, but I did two simple things, which may prompt thought / improvements: I ran a static analyser over your code (clang-tidy V9). The output is below. It is pointing many of the stylistic things I would say too. And it highlights some actual issues. I added a main() method and i tried to use your ...


2

I feel like the implementation of the class would be simpler if backed by a std::array<value_type , Size> instead of value_type _buffer[Size];, because then you could use the standard algorithms (aka iterators) easier, and get bounds checking in debug builds (at least in MSVC). Initializing the buffer via : _buffer{} is unnecessarily slowing you down ...


1

Readability The vector initialization in main would be more readable if the {{ and }} were broken out onto separate lines. vector<vector<int>> nums = { {1, 1, 1, 0, 0, 0}, // 0 {0, 1, 0, 0, 0, 0}, // 1 {1, 1, 1, 0, 0, 0}, // 2 {0, 0, 2, 4, 4, 0}, // 3 {0, 0, 0, 2, 0, 0}, // 4 {0, 0, 1, 2, 4, 0}...


1

Overall Please fix the formatting. It's hard to find the public/private sections that way this is formatted. A fundamental miss of your dynamic array is that objects are not correctly created or destroyed. You use malloc() and realloc() to allocate memory. But these functions do not call the constructors on class type objects. Thus the memory is not ...


1

Since you're using malloc, realloc, and free for memory management, your class can only be instantiated with POD classes. Any class with a constructor, destructor, or copy assignment operator may not work with your myVector class because these special functions will not be called. The copy constructor is wrong. Since it uses copy assignment, and the copy ...


1

writeVoxelAsSTL takes unsigned arguments, but it seems like the native type is actually a long. Could it take longs instead? For example, unsigned(2^31) looks like it would not be a valid value since it would overflow into -1 upon conversion. You could take an ostream& argument instead so the code isn't coupled to files. You could factor out the bools ...


Only top voted, non community-wiki answers of a minimum length are eligible