Category "c++"

C++ STL vector for existing data

Can I create an std::vector using my pre-existing data instead of it allocating new memory and copying the data? To be clearer, if I have a memory area (either

initialize a vector to zeros C++/C++11

I know in C++11 they added the feature to initialize a variable to zero as such double number = {}; // number = 0 int data{}; // data = 0 Is there a simila

Understanding Hierarchy, from findContours opencv

I am trying to understand Hierarchy and findContours, from opencv c++, but am finding it difficult. I did go through this question here, but I still am not abl

Confusion about declaration and definition of static const data memebers

Scott Meyers writes in Effective Modern C++ (Item 30 page 210) that there's no need to define integral static const data members in classes; declarations alone

JPEG Compression using OpenCV

I'm trying to perform a basic JPEG Compression (DCT + quantization + IDCT) using OpenCV not using entropy-encoding/Huffman-coding. The problem is that after I d

cuda 10.2 in Qt 5.14 ubuntu 18.04

I am planning to start cuda programming in Qt framework. I would like to start with a simple example. system information : OS : ubuintu 18.04 LTS Qt version : 5

C++ concatenate two int arrays into one larger array

Is there a way to take two int arrays in C++ int * arr1; int * arr2; //pretend that in the lines below, we fill these two arrays with different //int values

accessing std::tuple element by constexpr in type

I would like to access to a tuple element at compile time by a value constexpr in the type #include <iostream> #include <tuple> #include <utility

Iterate through a C++ Vector using a 'for' loop

I am new to the C++ language. I have been starting to use vectors, and have noticed that in all of the code I see to iterate though a vector via indices, the fi

Benefits of header-only libraries

What are the benefits of a header only library and why would you write it that way oppose to putting the implementation into separate file?

Why does const have to be added to constexpr for a string literal declaration?

This declaration: char constexpr *const s = "hello"; Fails with this error: g++ -g -Wall -Werror -std=c++17 test.cc -o test test.cc:8:31: error: ISO C++11 d

What is the C++ equivalent of Python's "in" operator?

What is the C++ way of checking if an element is contained in an array/list, similar to what the in operator does in Python? if x in arr: print "found" els

Can we have recursive macros?

I want to know if we can have recursive macros in C/C++? If yes, please provide a sample example. Second thing: why am I not able to execute the below code? Wh

Using GLAD for Raspberry Pi project

I am trying to figure out how to create a window for my project. I want to work with OpenGL ES and I found online guides on how to use X11 and EGL for creating

Why can't a weak_ptr be constructed from a unique_ptr?

If I understand correctly, a weak_ptr doesn't increment the reference count of the managed object, therefore it doesn't represent ownership. It simply lets you

How to use enums in C++

Suppose we have an enum like the following: enum Days {Saturday, Sunday, Tuesday, Wednesday, Thursday, Friday}; I want to create an instance of this enum and

In Vulkan, is it beneficial for the graphics queue family to be separate from the present queue family?

As far as I can tell it is possible for a queue family to support presenting to the screen but not support graphics. Say I have a queue family that supports bot

Serialization without Boost.Serialization

I'm trying to implement a simple serialization/deserialization method for my code to be able to pass an object over the network using MPI. In an ideal world I w

What does "Cannot overload functions distinguished by return type alone" mean?

I have this code: In the header: ... int32_t round(float v); ... and in the source ... int32_t round(float v) { int32_t t = (int32_t)std::floor(v);

How to override other windows application's elements? [closed]

Can you please point me into the right direction? I want to edit other application textbox or click, programmatically. For example, in a web