Quantcast
Channel: User HolyBlackCat - Stack Overflow
Browsing all 946 articles
Browse latest View live
↧

How do I use SDL2 in my programs correctly?

I want to make a game using SDL2, but I'm unable to compile and/or run my code, please help!SDL2 is notoriously hard to set up, and it's often the first library aspiring game developers try to use.This...

View Article


Answer by HolyBlackCat for How do I use SDL2 in my programs correctly?

This answer is about MinGW / GCC, and not Visual Studio.This answer only applies to Windows.Common errorsThe common errors are:SDL.h: No such file or directory (when compiling)Various SDL_main...

View Article

Answer by HolyBlackCat for How can I swap two variable's value considering...

(1) is the correct option.(2) doesn't compile, and I have no idea what was your intent there.(3) is pointless. Firstly, it can overflow and cause undefined behavior. There's a similar technique called...

View Article

Answer by HolyBlackCat for How to access template parameters?

The only other option is a template with a specialization to extract the argument:template <typename T> struct GetSize {};template <std::size_t N> struct...

View Article

Answer by HolyBlackCat for How do you std::round doubles, but round towards...

#include <cmath>template <typename T>T absmax(T a, T b){ return std::abs(a) > std::abs(b) ? a : b;}template <typename T>T round_ties_towards_zero(T x){ return...

View Article


Answer by HolyBlackCat for C++ Function templates call itself and get stuck...

func<__Ts...>(obj); - here, despite you manually specifying the template arguments, the compiler still performs deduction and appends one extra type to the pack, based on obj's type. Apparently...

View Article

`error: exception specification of 'operator()' uses itself` when dealing...

Consider following code:run on gcc.godbolt.org#include <string_view>struct Iter{ Iter() {} Iter(std::string_view) {} Iter begin() const { return *this; }};It's a stripped down iterator, which is...

View Article

What are MSYS2 environments? How do I pick one?

MSYS2 is said to have different environments.What are they? How do I choose which one to use? What's the difference between MINGW64 and UCRT64?(This Q&A is intended as a canonical duplicate on this...

View Article


Answer by HolyBlackCat for C++ mark arithmetic hard-coded fraction as...

You're starting with a wrong premise.All three major compilers (Clang, GCC, MSVC) generate worse assembly with constexpr variable when optimizations are disabled, and the same assembly when...

View Article


Answer by HolyBlackCat for Redefining swap function in inherited classes?

Since the derived class doesn't add any fields, it shouldn't provide a custom swap at all. The one from the base class will be used automatically.If it did have extra members, the swap should've been...

View Article

What is the significance of 'strongly happens before' compared to '(simply)...

The standard defines several 'happens before' relations that extend the good old 'sequenced before' over multiple threads:[intro.races]11 An evaluation A simply happens before an evaluation B if...

View Article

Answer by HolyBlackCat for What is the significance of 'strongly happens...

Here's my current understanding, which could be incomplete or incorrect. A verification would be appreciated.C++20 renamed strongly happens before to simply happens before, and introduced a new, more...

View Article

Answer by HolyBlackCat for How to compare string when precompile

You have two options:Use numbers instead of strings, and give them names using macros:#define HELLO 1#define ASDASD 2#define MY_MACRO HELLO#if MY_MACRO == HELLO// ...#endifDon't use preprocessor, use a...

View Article


Answer by HolyBlackCat for C++ Define member functions for all template...

In C++23 you can use a templated explicit this parameter in same_function in the base class:struct CommonBase{ // equivalent to: // template <typename T> void same_function(this const T...

View Article

Answer by HolyBlackCat for g++ ok but clang no: return rvalue to lvalue

This is legal since C++23, see P2266R3. GCC 13+ and Clang 13+both implement it (both accept your code in C++23 mode), while MSVC doesn't yet.This paper (among other things) extends the implicit move...

View Article


Answer by HolyBlackCat for Is the ordering of...

It's guaranteed to be depth-first traversal. (But the file order in each individual directory is of course unspecified.)The first hint is the existence of .disable_recursion_pending(). It would be hard...

View Article

Answer by HolyBlackCat for Makefile Pattern recipe for filename copying and...

Alright... Here's the function to convert a string to uppercase:override alphabet := \ A-a B-b C-c D-d E-e \ F-f G-g H-h I-i J-j \ K-k L-l M-m N-n O-o \ P-p Q-q R-r S-s T-t \ U-u V-v W-w X-x Y-y \...

View Article


Answer by HolyBlackCat for How to pass a template parameter to an object...

The only way to achieve the log<i> << ... syntax is to make log a variable template. Note that this will break log << ... and log.Foo() syntax.#include <iostream>#include...

View Article

Answer by HolyBlackCat for What do each memory_order mean?

Firstly...Things to ignore:memory_order_consume - apparently no major compiler implements it, and they silently replace it with a stronger memory_order_acquire. Even the standard itself says to avoid...

View Article

Answer by HolyBlackCat for Why deleting an element in a linkedlist costs O(1)

There's no reason why you have to start with a pointer to the node itself. You can work with pointers to preceding nodes.

View Article
Browsing all 946 articles
Browse latest View live




<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>