General C++ Programming - May 2020 (Page 2)

TicTacToe and Magic Squares
 
Here's cool trick for determining a winner in tic-tac-toe with just 5 lines of code. It's from a 1978 letter by Mike Richter, page 8 of the PPC Journal V5 N1 wh...
[4 replies] Last: Lastchance and Dutch, those are nice solutions. Thanks. The magic squ... (by dhayden)
Help with hexadecimal math (1,2)
 
I'm working on a personal project where I have 2 bytes in hexadecimal code (25B0) representing animation data that rotates the roll of a 3d object. The 0 repres...
[21 replies] Last: << and >> is the same as multiply/divide by 2? yes. lets take a... (by jonnin)
Cross-platform CMAKE project for old VESA/SVGA DOS Graphics
 
Hello everyone, I've a lot of old code that I used to do in my school days. Those code maily used TurboC and DJGPP. For Graphics I mainly rely on Interrrupt 10...
[2 replies] Last: I want to port them to modern OS Very good learning experience, porti... (by George P)
Confused on Lock-Free Stack (Linked List) implementation
 
In C++ Concurrency in Action, 2e, The author describes a lock-free thread safe linked list implementation. Right now, he is describing the pop() method and how ...
[15 replies] Last: In order for a use-after free No, it doesnt have to be used within t... (by TheToaster)
Migrate C ++ application from jsoncpp to rapidjson.
 
I have to modify a linux C ++ application developed some time ago, which use the jsoncpp library so that it uses rapidjson instead. The original application...
[2 replies] Last: Thanks. I have to study the operation of jsoncpp and rapidjson in two... (by jstechg)
List
 
#include <iostream> #include <list> using namespace std; template <typename T> class Set { private: list<int> storage; public: size_t size() const { return s...
[3 replies] Last: If you need fast random-access you could use std::vector instead of st... (by Peter87)
by F8Code
Cout's don't appear after adding a loop
 
Hello, this is my first post on cplusplus.com I'm making my first ever game, and I have a problem with one of my functions. This is the function: void skull(i...
[3 replies] Last: Your score decoration loops are messy one-liners, hiding a bug. #inc... (by salem c)
Purge and preset over again a static variable
 
How to purge and preset again a static local variable in function from an initiative outside of it?
[1 reply] : I don't know what you think "purging" a variable is, but maybe this: ... (by dutch)
intersection of two circular lists
 
Hello everyone! Please help with writing a program. It's Very necessary. Write a program Intersection of two cyclic lists. Knowing that Intersection - the resul...
[4 replies] Last: if the lists are massive, you need to make one of them easy to search ... (by jonnin)
by Argi
Instantiating derived class causes crash?
 
Hello, I'm facing a rather strange problem that I need help on solving... So when I instantiate a derived class (HomePC, GamingPC or WorkstationPC) from the bas...
[5 replies] Last: Yep, I get it now guys. Honestly I never would have noticed that on my... (by Argi)
by frek
My vector "myVec"
 
Would you, please, review my class myVec (to its point here), and tell my why I get the error:" type name is not allowed " for " throw invalid_argument; ": ...
[4 replies] Last: [quote=TheToaster]1.) Yes. Assuming of course that the class is defaul... (by MikeyBoy)
How to do it?
 
The function reads text from words from a file and returns a two-level dynamic array of pointers to lines to lines containing words from the source file, sorted...
[1 reply] : Break it down into tasks: 1) Create a "two-level dynamic array" of p... (by MikeyBoy)
Constructor Destructor
 
My code is: #include <iostream> #include <random> #include <functional> template <typename Key> struct treap_node { Key key{}; // {} invokes default construc...
[8 replies] Last: [code firstline=23] treap() { treap<int> my_tree = {1,2,3,4... (by MikeyBoy)
C++20: The Unspoken Features
 
The article on C++20 features that you probably haven't heard of. Highly recommended!:) https://humanreadablemag.com/issues/3/articles/cpp20-the-unspoken-fe...
[1 reply] : I had heard about most of them but interesting features nevertheless. ... (by Peter87)
Track memory on heap (Garbage Collection)
 
how to trace memory leak in c++? Suggest some method to individually trace memory taken by objects in heap?
[5 replies] Last: I personally think implementing garbage collection in C++ in counter p... (by malibor)
by frek
Copy assignment definition (1,2,3)
 
Hello all, Please take a look at this class, Vector: class Vector { private: double* elem; // elem points to an array of sz doubles int sz; public: Vector(int...
[50 replies] Last: Thanks to all so much. :) (by frek)
QuickJS
 
Hello! I am trying to embed QuickJS into my Visual Studio 2019 project. It works fine except it cannot find the files <dirent.h>, <unistd.h>, and <sys/time.h>. ...
[4 replies] Last: Right, I will check it out. Appreciate the help :) (by hassanAman)
sorting with pair
 
H I am trying to sort a text file either based on the first or second. So I would ask the user whether they want to sort by the first or second then it created ...
[9 replies] Last: You can indeed sort descending by switching < to >. @andywestken is r... (by lastchance)
How do we have extern for a member of enum
 
how to have extern for a member of enum tried int type of it failed as it's used in a cpp including an .h : extern STATES TO_STATE; has definition in s...
[4 replies] Last: Any enum can be forward-declared when its underlying type is specifi... (by mbozzi)
Size of Array of Vectors in for loop
 
This is a portion of my code: [code firstline=10] int charIs(char input) { vector <char> list = { {'a', 'b', 'c'}, {'d', 'e', 'f'}, {'g', 'h', 'i'}...
[4 replies] Last: This should work: int charIs(char input) { std::vector<std::arra... (by malibor)
May 2020 Pages: 1234... 9
  Archived months: [apr2020] [jun2020]

This is an archived page. To post a new message, go to the current page.