General C++ Programming - February 2021 (Page 3)

writing a singly linked list to a file
 
Hello, I have the following singly linked list class: class singlylinkedlist1 { public: node* head; singlylinkedlist1() { head = NU...
[11 replies] Last: Ok, I am putting some of my code in summary (I didn't include the node... (by gevCplus)
by brim4
How to read a text file of varying line size into a data structure?
 
Hiya. I am attempting to read some data from a text file into an array. I noticed that I can not do it the traditional way as the names are of different lengths...
[3 replies] Last: An alternative take is to use a vector<int> for the marks so that any ... (by seeplus)
[HELP] how to read a file byte by byte
 
I want to open a gif file from the laptop and read it byte by byte to read the header and other sources contained in a file. I opened a file using the code belo...
[1 reply] : Something along these lines: #include <iostream> #include <fstream>... (by JLBorges)
How to deduce a native array in a template function?
 
Hi, I used to know this but I think I am just exhausted. I want something like this: template<int N, int array > static bool anyNonZero( int (arra...
[4 replies] Last: Thanks!!!! (by JUANDENT)
by VoB
On returning references to local objects and subscripting operator. (1,2)
 
I need a check about returning a reference. In particular, I have two questions. It's well known that we should never return references to local objects. F...
[31 replies] Last: Fair enough. (by helios)
virtual classes confusion
 
I have this design (the basic dreaded diamond): class base{ public: base(const char* label) : m_label(label){}; virtual ~base(){}; voi...
[2 replies] Last: Thanks, Ganado. After I read your reply, I found this as well @https:/... (by daytooner)
Pre-allocated memory data for parallel threading keeping locality
 
Dear experts I think this post seems ambiguous and case-by-case question. But, if you have know-how, I would appreciate it if you could help me. I think pro...
[6 replies] Last: Today, I did performance check in NUMA-arch machine (Xeon Gold) and no... (by Mitsuru)
How to take this Python code and convert it into C++: list(product([True, False], repeat=len(some list)]))
 
I've been thinking hard on this idea of how to replicate itertools.product. Any thoughts?
[6 replies] Last: the trouble is the problem is in a vacuum ... now that you generated i... (by jonnin)
Creating objects and downcasting them in the same line?
 
I am trying to create an object and downcast it in the same line. But I am getting errors with Child *cp= dynamic_cast <Parent *> new Parent(); #include<iostre...
[1 reply] : Of course it throws an error. A Parent is not a Child. You would like... (by keskiverto)
How does cache of function calls work?
 
Dear experts, I am now understanding how cache works, and suitable "data" structures (e.g. contiguous data array, stack memory region etc). Here, I am wonderi...
[8 replies] Last: Dear dhayden Thank you for your reply. I would like to be oblivious a... (by Mitsuru)
by EmanCS
min_element : returning all instance
 
Hi I have a list of structs the struct has fields a,b,f StructName struct1 = *min_element(myList.begin(), myList.end(),&ClassName::_compareObjectiveF); _com...
[1 reply] : Unless they happen to be ordered by f, it's not possible to return the... (by dutch)
Socket Programming, Casting sockaddr_in to sockaddr. Why?
 
Here is a sample socket programming snippet from the client side. My question revolves around the type-casting that casted sockaddr_in into sockaddr. My questio...
[1 reply] : Use code tags when posting code. sockaddr is a generic structure that... (by dutch)
by frek
Infinite for loop
 
The question is, why the loop below falls into an infinite cycle. #include <iostream> void infinite() { unsigned char max = 160; // very large for ...
[5 replies] Last: 1) - Wrapping around 2's complement is the most likely scenario, whic... (by Ganado)
Hashing way of bounded non-sequential index for contiguous data structure
 
Dear experts I am amazed at performance promotion by using contiguous data structure (std::vector) instead of linked data structures. I often have no choice b...
[4 replies] Last: Dear JLBorges Thank you for your profound reply. I am willing to con... (by Mitsuru)
Best book or documents for vectorization (SIMD operations in) for C++
 
Dear experts I am studying the best way to use vectorization (SIMD), in order to achieve thread&SIMD parallelization as Intel proposes the potential of speed u...
[4 replies] Last: Dear keskiverto Thank you for your advice in auto-vectorization. At ... (by Mitsuru)
Final State Machine
 
I tried to code a traffic light. What I have so far is somewhat where I think, it could be a FSM. But I'm not sure about if it would be such. Also, I have some ...
[6 replies] Last: #include<iostream> #include<thread> #include<chrono> #include<windows... (by lastchance)
Linked list in a linked list question
 
Hello, I want to implement a <<singly linked list in a singly linked list>> data structure. I coded my singly linked list but I find it difficult to make each ...
[4 replies] Last: @dutch: Thanks a lot! It didn't cross my mind at all to use templates!... (by gevCplus)
by opfabi
multiply the odd numbers from a file
 
hi, I am trying to multiply the odd numbers from a file using a recursive function and I don't quite know how, I've tried several times but it just doesn't work...
[4 replies] Last: #include <iostream> #include <fstream> #include <sstream> using names... (by lastchance)
Multiple inheritance is bad?
 
I'm implementing a simple game, and I have a trouble with class architecture. Assume that you implement a object class, and you want to separate some feature. ...
[3 replies] Last: Thank you guys. I thought too that many people say something is bad, b... (by woohyeon)
Enum type as a member variable.
 
Hi. When you use enum type as a member variable, what do you use for the member variable's real type? I mean, If you want a variable for a color, you will...
[13 replies] Last: jonnin // Thank you for your advice! I understood that I have to choos... (by woohyeon)
February 2021 Pages: 123456
  Archived months: [jan2021] [mar2021]

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