Hot answers tagged

3

Use the force library Luke! Your code does use std::vector, but for reasons I don't understand, it also uses new to allocate a manually managed dynamic array as well. You don't seem to gain anything from this, so I'd advise using std::vector throughout. I'd also look at the standard library's algorithms. Some of them (e.g., std::remove_copy_if) could be ...


2

I want to expand on the idea that tuples are a bad way to organize data. Programming languages have decades of history of making better ways to describe data that is more readable and easier to understand. tuple does away with those decades of work and makes code way more confusing and harder to understand. For example, let's look at your data types: ...


2

I can't say for sure what the interviewer thought, but here are some things that could be improved: 1) Use appropriate data types CountryList is acceptable, but Container should be a class, not a tuple that requires referring to the (hopefully correct) comment to see what data get<1> is referring to. And what is ContainerList even indexing by? Based ...


2

High powers of small-magnitude numbers tend toward zero. When you get subnormal floating-point numbers, then there's a heavy speed penalty; this point is reached sooner with double than with long double (and reached even sooner still using float). A simple way to improve the speed may be to disable subnormals for this function - e.g. compile with g++ -...


2

I accidentally deleted my first review, so this will only cover the main points: bug: I think this is the main reason your code doesn't work. Flushing isn't the issue. void operator<<(int data) { auto child = static_cast<childClass *>(this); child->FromSerial(data); } void operator>>(int data) { auto child = static_cast<...


1

Since writeTo does not modify v, it should take that parameter as a const reference (const std:::vector<T>&v). In LineEditor, the constructor doesn't initialize ary, so if you construct a LineEditor object and destroy it without calling removeLines (or if that function returns, possibly by an exception, before you allocate the memory) you'll ...


1

I find your code very dense and difficult to skim. I think you can help it quite a bit by making sure each statement is on a line by itself; that there's whitespace around your operators; and that you use std:: qualification on standard library types and functions. More controversially, I would say "don't abuse foo++ to mean foo += 1" — the shorthand ...


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