C++ on Stack Overflow and Game Dev

7 answers

Mutex example / tutorial?

I'm new to multithreading, and was trying to understand how mutexes work. Did a lot of Googling and I found a decent tutorial, but it still left some doubts of how it works because I created my own ...

2 answers

Significant price difference while calculating call option price using Monte Carlo approach in C++ and Python?

I am trying to calculate the price of a european call option using the Monte Carlo approach. I coded the algorithm in C++ and Python. As far as I know the implementation is correct and as N (the ...

1 answer

Pass-by-reference hinders gcc from tail call elimination

See BlendingTable::create and BlendingTable::print. Both have the same form of tail recursion, but while create will be optimized as a loop, print will not and cause a stack overflow. Go down to see ...

10 answers

How to swap two numbers without using temp variables or arithmetic operations?

This equation swaps two numbers without a temporary variable, but uses arithmetic operations: a = (a+b) - (b=a); How can I do it without arithmetic operations? I was thinking with XOR

10 answers | 7 mins ago by mr_eclair on Stack Overflow stackoverflow.com
0 answers

Using MTL/Boost Library Mac Terminal C++

To be precise, I'm attempting to run this excellent project: https://github.com/ppwwyyxx/panorama I'm using a modern mac. The issue is that I can't seem to get my computer to properly include the ...

2 answers

How to render a red push button using QStyle.drawControl()?

With the following code I tried to render a red push button using QStyle.drawControl(): #include <QtCore/QtCore> #include <QtGui/QtGui> class Widget : public QWidget { virtual void ...

2 answers | 19 mins ago by user763305 on Stack Overflow stackoverflow.com
0 answers

Using GL_TEXTURE_2D_ARRAY crashes the program

First, I create a 2-D array of textures: int arrayId = textureArrays.size(); textureArrays.resize(arrayId + 1); textureArrays[arrayId].ImageWidth = ImageWidth; textureArrays[arrayId].ImageHeight = ...

0 answers

OpenGL Quad Tessellation - What kind of VBO?

I'm just getting into tessellation and after drawing and tessellating a triangle, I want to try a quad. If I change the TCS to output 4 vertices, the TES to expect a quad and the patch size to 4, only ...

0 answers

QTabBar keep last tab fixed

I added a "new tab" button to the right tab using the QTabWidget addTab method. On multiple tabs a truncated tab bar shown and hides the last tab. I tried to set the ...

1 answer

'sensor_l_value_last' does not name a type

I am writing a long program on arduino to ''help the blind see'' using ultrasonic sensors. The last 2 lines of the whole code is: sensor_l_value_last = sensor_l_value; sensor_r_value_last = ...

1 answers | 24 mins ago by Chukwubuikem Obiezidi on Stack Overflow stackoverflow.com
1 answer

Lua “attempt to index a nil value”

I'm trying to register a vector type with Lua, but I'm getting a strange "attempt to index a new value" error when I'm calling the addition metafunction from Lua. Here is the code section involved, ...

1 answers | 26 mins ago by Therhang on Stack Overflow stackoverflow.com
5 answers

Generic function dispatch mechanism

I am trying to write a generic function dispatch mechanism where I do some additional work before calling the actual function (e.g. time the function's execution). The following code works, except for ...

5 answers | 27 mins ago by Omair on Stack Overflow stackoverflow.com
1 answer

Issue C1083: cannot open include file: 'chrono': no such file or directory pops out

I'm trying to make a program that makes 6 numbers come out randomly. This is my .pro file QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Lotto TEMPLATE = app CONFIG ...

1 answers | 27 mins ago by apolokr2000 on Stack Overflow stackoverflow.com
0 answers

Unable to link an executable to shared library

I have a cmake project where I am trying to link the executable to the shared library. But it is not getting linked. After searching enough and not finding any useful solutions, I'm posting my ...

0 answers

OpenGL Quad Tessellation - What kind of VBO?

I'm just getting into tessellation and after drawing and tessellating a triangle, I want to try a quad. If I change the TCS to output 4 vertices, the TES to expect a quad and the patch size to 4, only ...

0 answers

OSX pushing pixels to screen with minimum latency

I'm trying to develop some very low-latency graphics applications and am getting really frustrated by how long it takes to draw to screen through OpenGL. Every discussion I find about it online ...

1 answer

unit test in eclipse g++

I am using Eclipse to develop some projects and implement unit test by using google test. everything was fine this morning. I can build project and run unit tests. however, after i commit the local ...

1 answer

The most efficient way to resize cv::Mat

all I'm writing an image processing program, which uses cv::resize(INTER_LINEAR) hundreds of times for one frame. However, I found cv::resize() is a cpu-killer and it is the hot spot in my program. ...

2 answers

repeated extern declarations of qualified identifiers C++

Why is it that qualified names cannot be re-declared inside functions? The following code fails to compile (in MSVC2015 and clang) int i; namespace N { int j; } void foo() { extern int i; ...

2 answers | 40 mins ago by Hector on Stack Overflow stackoverflow.com
3 answers

tr1::unordered_set union and intersection

How to do intersection and union for sets of the type tr1::unordered_set in c++? I can't find much reference about it. Any reference and code will be highly appreciated. Thank you very much. Update: ...

3 answers | 46 mins ago by Ross on Stack Overflow stackoverflow.com
2 answers

How to set a value in an unordered_map and find out if a new key was added

How can I efficiently and idiomatically set a value in an unordered_map and find out if a new key was added: #include <unordered_map> #include <string> int main() { auto map = ...

0 answers

Error message: Serial communication between c++ GUI and Arduino

I am about to program a c++ GUI application (wxWidgets) to control an Arduino. I want to use the SerialClass.h and SerialClass.cpp from the Arduino playground site ...

1 answer

assigning members of a pair to variables

Is it possible to assign the members of a pair without creating a temporary object? #include <tuple> using namespace std; pair< bool, int > foo() { return make_pair( false, 3 ); } ...

1 answers | 55 mins ago by Hector on Stack Overflow stackoverflow.com
0 answers

Converting callback from C++ to C++/CX

In code I am porting I have this function which takes function as an argument: void doSomething(std::function<void(std::string)> callback) Could you please tell me how to implement this ...

1 answer

How to make static class function return non-const reference

Question: How can I return a non-const ref from a static class function, and why is the code below not doing so? I am trying to initialize vectors with a custom allocator that itself is initialized ...

1 answers | 1 hour ago by sunny on Stack Overflow stackoverflow.com
3 answers

C++ Use of deleted function error

I'm getting a lot of use of deleted function error. I just changed the pointer of weighted_pointer to unique_ptr. But I can't realize why I'm getting the error, any tip? The likeatree is a DAG ...

1 answer

Visual Studio 2013 error MS8020 Build tools v140 cannot be found

I had previously been using VS2013 express without issue, but suddenly it began crashing whenever I tried edit the code while it ran existing code fine. I tried uninstalling and switching over to ...

1 answer

Cubic Bézier: What to do when leading coefficient is zero?

I use a fairly standard method to retrieve the monic polynomial coefficients from a cubic Bézier curve's control points: std::array<double, 3> getBezierCubicCoefficients( const ...

1 answer

How to create an array of objects which are NOT move/copy constructible

I run into trouble if I would create an array of objects like this: SM sc[8]{{0},{1},{2},{3},{4},{5},{6},{7}}; The constructor for SM is defined as: SM::SM(int); Because in c++ Each member is ...

1 answers | 1 hour ago by Klaus on Stack Overflow stackoverflow.com
3 answers

C++: How to create an abstract base class if class has no member functions?

I have an abstract base class, which serves the purpose of allowing an array of pointers to a base class to be created. (Useful for 'many things'...) My abstract base class contains no member ...

15 30 50 per page
1 2 3