Most voted "c++11" questions
C++11 is the standard C++ language approved in 2011. It replaces the previous C++03, adding several novelties to the language, such as Lambdas, auto deduction of variable types (`auto`) and threads.
Learn more…88 questions
Sort by count of
-
25
votes2
answers4341
viewsWhat are rvalues, lvalues, xvalues, glvalues and prvalues?
Prior to C++11 there were only two value categories for expression tree types: lvalue and woodland. Quite simply, the first represents a reference that can be changed and whose address can be read,…
-
17
votes5
answers453
viewsIs it legal to delete this in a member function?
The language delete this serves for an object to commit suicide. For example: void Recurso::release() { --refs; if (refs == 0) delete this; // Aqui o 'this' pode ser um ponteiro inválido, // tocar o…
-
15
votes1
answer170
viewsWhat is the use of "= delete" in the declaration of a constructor in C++?
I came across a builder declared as follows: State(const State& em) = delete; Does anyone know what the = delete at the end of the signature of the manufacturer?…
-
10
votes2
answers517
viewsHow does Std::move work?
I would like to understand the operation of std::move. I realized that with the C++11 specification comes this new function, as well as now we have a new operator (&&). What is the semantics…
-
10
votes3
answers540
viewsWhat kind of smart pointer to choose?
How to know what kind of smart pointer to use? And what’s the difference between them? Example: std::unique_ptr<MinhaClasse> mClasse(new MinhaClasse) std::shared_ptr<MinhaClasse>…
-
9
votes1
answer574
viewsWhat is Explicit in C++?
I came across the term explicit being used in a C code++. What is the use of this keyword?
-
8
votes3
answers784
viewsSet the threads priority in C++11
In the program I’m developing I have two Std::threads that are always active throughout the life of the program. However, I consider that the role of one of them is of minor importance and would…
-
8
votes2
answers391
viewsC++ (basic): for, references and syntax
My teacher presented this function to us: void escala(std::vector<double> &v, double fator) { for (auto &vi:v){ vi *= fator; } } It serves to multiply all the elements of a vector by a…
-
8
votes0
answers77
viewsWhat is a Memory Model?
Reading the Wikipedia article in English discovered that Java was the first popular language to have a memory model in the presence of well-defined threads, followed by C++11. Reading the article in…
-
7
votes1
answer2547
viewsWhen to use void* and auto*?
C++11 provided us with the type auto (Automatic). It can transfer type for the first time. But before it, people used to use the void*, where you referenced on the pointer. I still use void*…
-
7
votes2
answers1064
viewsLambda functions in C++, when to use and what are the advantages?
When choosing to use a lambda function or a normal function, and what is the advantage of using a lambda function compared to a normal function? There is the call price of a function in a lambda…
-
7
votes1
answer2353
viewsAnalyze whether a number is even or odd
The program must do: Digite um Número: 12345 1 e ímpar 2 e par 3 e ímpar 4 e pra 5 e ímpar So far I’ve made the following code: void parImpar (int num) { int resto; while (num > 0) { resto =…
-
6
votes2
answers142
views -
5
votes1
answer459
viewsWhat is a shared_ptr?
If possible, with an example of code, as this is missing in the reference to really understand when and how to use the shared_ptr.
-
5
votes1
answer65
viewsWhy does Std::Ceil produce different results for float and double?
Follows the code: #include <iostream> #include<math.h> using namespace std; int main() { float calculo = 4.347 * 20 * 100; double calculo2 = 4.347 * 20 * 100;…
-
4
votes1
answer92
views -
4
votes1
answer506
viewsVariable without initializing
I did a basic function of squaring (exercise of a book), and I use a variable named aux and the use to calculate the power value squared, but the compiler claims that aux is not initialized, I would…
-
4
votes1
answer90
viewsPass lambda expression on command line
I created a program to calculate the defined integral of a function, but I want to be able to run it through the terminal. #include <iostream> #include <functional> #include…
-
4
votes2
answers76
viewsFind() function of the set library does not return whether or not it found
I’m writing a little program for a college exercise and I’m having second thoughts about find(). I must enter two integer numbers, check if the first number exists within the set previously defined.…
-
3
votes1
answer1169
viewsHow to create an object with class template?
I have this code: Main.cpp Warehouse<Base<int>> arm(1, 1, 1, 1); arm.createSubBase(1,1,1); Warehouse. h private: vector<Base<T>*> whouse; public : void createSubBase(int,…
-
3
votes1
answer701
viewsWhat are C++ pointers really used for?
Where pointers are actually used? I’ve searched so many places and the example is always theoretical. I would like to know a real situation, an example within a real project in which pointers are…
-
3
votes1
answer628
viewsCode for earlier than expected
Follow the code with my suspicions: Header: class Name_pairs { public: void read_names(); void read_ages(); void print() const; void sort(); // Ordenar os nomes com as idades private:…
-
3
votes2
answers1115
viewsTreatment of exceptions in C++
I have a question regarding the treatment of exceptions in C++, the class Fracao below is purposely incomplete does not even possess setters or getters and several things have been "set aside", has…
-
2
votes1
answer572
viewsObject-Oriented Multithread in Native C++11?
How is implemented the Multithread Orientado a Objetos in C++11? in java this is possible through the Class Extension Thread / Implementation of the interface Runnable and overwriting the Run Method…
-
2
votes1
answer335
viewsHow to make a Sorting in classes?
Funny thing is, that was an answer! The problem I have is this: I have a Person class, which initializes with a string, and it splits into a number and another string. After the class is mounted, I…
-
2
votes1
answer326
viewsHow do I stop a for loop that stores the values of strings typed in C++?
So I’ve tried everything I’ve tried to compare type typed a "." or set a limit value and even then the program does not continue, it stays inside the infinite loop. The code comes next:…
-
2
votes1
answer61
views -
2
votes1
answer420
viewsProblem with operator overload
Errors occur when I step the class object Name_pairs by the exit operator << and by the comparative operator ==. Header: class Name_pairs { public: void read_names(); void read_ages(); void…
-
2
votes1
answer195
viewsSearch text in a String as a "like"
I want to do a text search, like the ones I do in Mysql. Ex: LIKE "9%4" I tried to implement a find_if(), but without success. #include <iostream> #include <string> #include…
-
2
votes1
answer245
viewsHow do I add a value to a struct vector, for example in some vector field, because it is from a struct
#include <iostream> #include <vector> using namespace std; struct dados { int pessoas; int consumo; }; int main() { int totalx=0, totaly=0; int n,x,y; vector<dados> info; //int…
-
2
votes1
answer73
views -
2
votes3
answers606
views -
2
votes2
answers55
viewsCan you add the keyword "noexcept" in get/set methods?
Is there any problem in adding to keyword noexcept in methods getters/setters of a class that only returns or changes values of simple variables (bool, int, float, double, etc..)?…
-
2
votes0
answers490
viewsEliminating repeated values from a vector
Hello, folks briefly my problem is to eliminate repeated values of an array, here is my code and just below a brief explanation.…
c++11asked 7 years, 9 months ago Jhonattan Cabral 51 -
2
votes0
answers129
viewsQuestions related to an anti Cheat system
I have not found a better way to describe the title of the topic, if it is not good enough, I ask that moderation edit it for me. I have some questions related to an effective anti Cheat system for…
-
2
votes1
answer200
views -
2
votes0
answers63
viewsSimulate a mouse click using X11
I’m trying to simulate a mouse click using the X11 library on linux. Using the command xev in the terminal I have the following exits. For a real click: ButtonPress event, serial 32, synthetic NO,…
-
2
votes1
answer154
viewsSort from minor to major in priority_queue unpacking by second element, is it possible?
I’m studying priority_queue and a question has arisen, if I want to insert in the priority queue a pair of elements, how do I so that the queue shows the element with the smallest number and if it…
-
1
votes1
answer73
viewsIs it possible to create an Std::list with an initializer_list?
I’d like to pass one std::list temporary to a function, but do not know if it is possible to do it. I know it is possible to pass a std::vector temporary with a initializer_list: #include…
-
1
votes2
answers104
viewsProblems with extensive algorithm
I don’t know what to do, I think I made a mistake I don’t know. In my program the user must think of a number, and the computer must try to guess which number the user thought. The computer may ask…
-
1
votes1
answer111
viewsHow to use a constructor with two or more classes?
I am developing an object-oriented library. I created an iterator for my future container. I have advance_iterator and regress_iterator. Both give rise to bidirectional_iterator. The code is:…
-
1
votes1
answer139
viewsExecute commands in a C++ string
I have commands in a string something like: string comm = "int x; cout << \"Digite um número\"; cin << x;"; My idea is to execute the commands that are in this string, having the result…
-
1
votes1
answer59
viewsHow to define a subclass of an abstract class so that it is concrete
With these classes: class SerVivo { public: virtual void funcA() = 0; virtual void funcB() = 0; }; class Vegetal : public SerVivo{ public: virtual void funcB(){ cout << "funcB em Vegetal \n";…
-
1
votes1
answer112
viewsBest way to distribute program using a Shared library
I wrote a program that uses a library called curlpp. The program is very simple and all it does is make an HTTP request that returns a JSON (use the curlpp to perform this request), parse this JSON…
-
1
votes1
answer89
viewsHow to find something specific inside a Text file
Hello, I have to check the grades of a certain student and if his average is greater than 5 show the name so I have no idea how to do it... nor to ask how does it so excuse me if I was unclear…
-
1
votes1
answer133
viewsWhat is the difference of declaring a variable as constexpr const and constexpr?
What is the difference of declaring a constant as constexpr const for only one constexpr? constexpr const float max_height = 3.0f; constexpr float max_height = 3.0f;…
-
1
votes2
answers691
viewsHow to avoid "Warning: ISO C++ forbids variable length array ːfilename' [-Wvla]" error in C++11
I have the following piece of code that aims to create a buffer for the file name that will be created based on some information provided at class instantiation: char fileName[size];…
-
1
votes0
answers78
viewsMethods that return constant values in C and C++ even if they come from variables, is it possible?
In a series of optimizations in a code written in C++ adopted a class to store application parameterization data and some pseuconstants let’s say so. What actually happens is that when the…
-
1
votes0
answers208
viewsFree(): invalid Pointer C++
Guys, I don’t understand why this code doesn’t work. Do you have a problem returning Multiconjunto m in the union method? This is a university task, so I can’t use standard library and the set has…
-
1
votes1
answer424
viewsHow to create a mapped file with an Std::map
I’m trying to use a Std::map that allocates objects within a file mapped using boost, with a vector worked but with a map not #include <boost/interprocess/managed_mapped_file.hpp> #include…