Why doesn't my << overloader work? And I am having problems understanding how to use std::async in C++. | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
- 2

Why doesn't my << overloader work? And I am having problems understanding how to use std::async in C++.

I am trying to make a program where it displays coloured images on the console BUT it takes a lot of time and the program will dump core. To prevent this, I can use threads. If I print 2 images at the same time, a mess will be created. I don't want that. I've heard of locking threads and mutex. I used it, now gives me 1000 errors. https://code.sololearn.com/cHpCK05dnzOn/?ref=app

10th Jun 2021, 4:46 AM
Purple Requiem
Purple Requiem - avatar
1 Réponse
+ 1
The problem is that you are passing a pointer to printImage(), but not dereferencing it, so you are missing one level of indirection (were some fun error messages though, I had to paste them into a txt file to see it all). Passing by const reference should suffice here. Another thing is that once you start with constant references, you need to be wary of what methods of your class should be const themselves so you can still call them from constant objects and references. Proper const correctness can go a long way. I overhauled the code a little and added some comments: https://code.sololearn.com/c0a23a18A2A1/?ref=app
10th Jun 2021, 8:44 AM
Shadow
Shadow - avatar