Hot answers tagged

9

This is what database software does. And it's quite good at it! Install your favourite RDBMS of choice - MariaDB, PostgreSQL, or whatever. Create your tables and indices. Write code to load the data in. Query it using SQL. Indices are very important. Indices are how RDBMSes find the right piece of data on disk without having to look through all the data. Set ...


6

The standard approach when implementing the command pattern with command objects, derived from some Command class, is to make any individual command arguments part of the constructor parameters. The commands themselves need to have a uniform public interface, but for the constructors, where the specific type of command is still known, this restriction does ...


5

The main cause of these sorts of error messages is C++ templates are all applied before you do the regular compiling, whereas most other languages that support it have parametric polymorphism built into the main type system. So, unfortunately, errors that cross that boundary can be infamously cryptic. They are getting better, though. In another 35 years it ...


5

You haven't missed anything. Some things are just difficult to do. Dynamic casts are not inherently evil, they are just fragile: if you add a DerivedC type, your casts will continue to work but just skip objects of this type with no compile-time error. This is very analogous to the issue that an Object::addTo(Inventory&) method would need to be kept in ...


4

Is it a skill to understand the errors given by the compiler? In general, yes. There's a lot of information packed into it, that you can extract into something more readable with practice. Smooth.h:63:15: error: You have an error on line 63, column 15. I Think this is just the start of the lambda, but any decent editor or IDE will show you. invalid user-...


3

Neither double nor long double are suitable for expressing fractional numbers. They are for floating point numbers, not fractional numbers. You should use a fractional number data type, something like this: struct fraction { intmax_t numerator; uintmax_t denominator; }; Instead of intmax_t / uintmax_t, you should probably use an arbitrary sized ...


2

I recently worked on this problem for a bytecode interpreter for a proprietary scripting language we use and managed some very nice improvements using a combo of techniques (unfortunately compiler-specific). I can't explain perfectly how and why they all worked to improve efficiency since I'm neither a compiler design nor a computer architecture wizard. ...


2

Why is that a problem? The lines of code are needed, it’s just sequential code, no benefit from splitting it up. I don’t like a giant main() so I would have a method “injectDependencies”. Maybe if there are clearly separate areas I would split it up, but there’s no huge benefit from it.


1

It's complaining because it cannot cast a Lambda Object to a pointer to a function. You nee to capture the function as a plain type (say X) then pass it through to another meta function to decide if its callable. template <typename X, typename enable_if = void> struct CallAble {}; template <typename X> struct CallAble < X , std::void_t&...


1

How do you break up any method that's gotten too big? By dividing it into submethods that each do a small contained subset of the whole algorithm. Whether we're talking about dependency registration or any other kind of logic is irrelevant. In the case of dependency injection, unless there is a high degree of top-level-application decisions being made1, I ...


1

I'ma jump in with the rude/controversial answer here and say the whole problem here is object-oriented oriented programming (not a diss on OOP in general, but here). You are trying to make a game with complex object interactions to my understanding. So you conceive of data you need and hide it all behind objects with these nice abstract public interfaces ...


1

I don't know about community consensus but I've come to favor not only using declarations but using directives (ex: using namespace std;) in source files (not for headers, of course, at namespace scope). At least Sutter seems to share the same wavelength. From his C++ Coding Standards: You can and should use namespace using declarations and directives ...


1

The comment that "performance" is an important factor is odd, because "performance" is not a single monolithic thing. The two most obvious different types of "performance" constraint are: Throughput (long-running servers, jobs that take a long time to complete, etc.) GC is typically good for this, since any overhead is ...


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