General C++ Programming - September 2022 (Page 3)

About function pointer as map's value
 
Hello everyone, like this code class A { public: A() {} void show() { } int a; }; void* CreateA() { return new A(); } int mai...
[6 replies] Last: > Doing an explicit cast seems to work but not sure if it's guaranteed... (by JLBorges)
std::format_args
 
It is my understanding that std::format_args requires compile-time stated arguments. Is it possible to generate a std::format_args variable in some way at run-t...
[4 replies] Last: Thanks. That's what I thought. This topic came up in conversations ove... (by seeplus)
why use std::decay?
 
Why is it necessary to use std::decay and std::forward here: template<typename T> auto f(T&& val) { using rawVal = std::decay<T>::type; rawVal* tmp = ...
[1 reply] : Roughly, std::decay a. removes cv-qualifiers, b. removes references,... (by mbozzi)
Debug build but with STL optimized like release build
 
Is it possible to compile the application code I write in a "debug" version (i.e. with symbols, ability to use breakpoints and step thru execution, watch variab...
[4 replies] Last: @Peter87: _GLIBCXX_DEBUG was a really useful tip. Thanks (by kbw)
Optimization: why is my Eigen code slow?
 
I just recently finished rewriting a code I had that used C++ arrays to include Eigen matrices instead. Unfortunately the Eigen code is slower. I read also that...
[18 replies] Last: In addition EcalcPotSourcek_inertia doesn't do anything as far as I c... (by JamieAl)
by Cplusc
variable can't be defined in namespace
 
Hello forum, I defined a header file name Cell.h as bellow, #pragma once #ifndef _CELL_H_ #define _CELL_H_ #include <iostream> #include <array> class Cell { ...
[2 replies] Last: Thanks for the answer. I appreciate it. (by Cplusc)
string issue
 
I am trying to solve the below problem. https://www.chegg.com/homework-help/questions-and-answers/amazonian-team-responsible-maintaining-monetary-transactio...
[10 replies] Last: Note that the sort order for treating the ids as strings or as numbers... (by seeplus)
by t im
Assign unsigned int to char
 
What will happen when assigning an unsigned int to char? Just as the code below: unsigned int num = 0x11223344; char* tmp = new char; *tmp = num >> 24;//0...
[1 reply] : A prvalue of an integer type or of an unscoped (since C++11) enumer... (by JLBorges)
by Geckoo
Sound by algorithm
 
There is a way to generate sounds according to an algorithm. It's very weird, but interesting. At the link below you can take a look at the principle with a lit...
[11 replies] Last: I didn't realize some orchestras tune their instruments to even higher... (by Ganado)
how convert position class to 'const POINT*'?
 
see my position class: class position { public: float X; float Y; float Z; float perespective; float foco; position(float posx = 0, float posy =...
[3 replies] Last: The operation you're specifying is on the collection, not the contents... (by kbw)
C++ LinkedList explanation
 
Please explain to me how these codes work. That will make me easily understand. Line# 11,12,13,14 Line# 26,27,28 Line# 40,41,42,43,44 #include "Stack.h" #inc...
[3 replies] Last: This code originally came from this post https://cplusplus.com/forum/g... (by seeplus)
How to create 3D matrix in Eigen
 
I am trying to build a 3D matrix in C++ using Eigen. I read online that instead of 3D matrix, I can create a Vector of 2D matrices. Which will help with perform...
[10 replies] Last: @jonnin Thanks again. (by JamieAl)
c++ special characters
 
I am trying to solve the below using c++. Any idea how to display special characters using STL and open source libraries? https://www.chegg.com/homework-help/q...
[16 replies] Last: Thanks everyone for your inputs,this thread can be closed. (by denver2020)
Buggy code
 
What is wrong in below code? class NonZeroSample{ protected: virtual intnxt = 0; public: int nxtNonZero() { int ...
[4 replies] Last: Thanks to clarify this. This thread can be closed. (by denver2020)
C++, Popped off
 
Hello, how to allow the user to enter how many items to be popped off? Please check my codes. #include <iostream> #include <stdio.h> using namespace std...
[4 replies] Last: Oh thanks i got it. (by raijin011321)
by Tima11
I get an error when trying to get value from the class in another class.
 
Hello. I get an error when trying to get value from another class which are also in one big class. Error: Type name is not allowed. Here is the actual code: n...
[3 replies] Last: Thanks keskiverto! I experimented with your solution to this problem a... (by Tima11)
Strange error in string::substr
 
I'm solving a problem in codeforces link: https://codeforces.com/edu/course/2/lesson/2/3/practice/contest/269118/problem/A I'm using two different ways to do s...
[16 replies] Last: I was thinking of Barbara Gaskin's version from 1981. (by seeplus)
Quick question on for loops header
 
I keep forgetting how this works: for (T<ItemType>* tempPtr = headPtr; tempPtr; tempPtr = tempPtr->getNext()) { if (tempPtr->getItem() =...
[2 replies] Last: Oh that's awesome, and powerful! It really is count controlled secretl... (by jetm0t0)
Linkedlist in a Class
 
Hello, please help me how do I put these codes in a class (.cpp and header file) #include <iostream> #include <stdio.h> using namespace std; class Node { ...
[8 replies] Last: Oh i see, its now working. Thanks a lot to those who help :D (by raijin011321)
For loop not iterating through array
 
Hey yall, got another question for everyone. I'm working on an assignment for class and I am trying to delete objects in some arrays (what the assignment is bas...
[16 replies] Last: yes, another great alternative. And, if you noticed, all the alternat... (by jonnin)
September 2022 Pages: 1234
  Archived months: [aug2022] [oct2022]

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