Questions tagged [c++11]
Use this tag for code that must compile as C++11 (not using any features introduced in C++14 or later).
55,434
questions
0
votes
3
answers
65
views
If statement giving parenthesis error in my triangle exercise
Learning C++ and doing a basic triangle exercise.
Can anyone check my code if I done everything right and explain why I am getting this error: suggest parenthesis around ‘&&’ within ‘||’
#...
-1
votes
0
answers
33
views
My code is giving me an error about "consteval type" not being allowed or something [closed]
I was just starting out with c++, when I immediately got an error.
This is my code:
#include <iostream>
consteval int get_value(){
return 3;
}
int main(){
constexpr int value = ...
0
votes
1
answer
60
views
How to get the type underlying std::complex<T> and use it in a class
I am writing a data processor, and would like to be able to perform real-to-real, and real-to-complex computations. The setup I have right now:
// class to hold various data types
template <...
0
votes
1
answer
39
views
Running into "error: [...] is a c++ extension" [duplicate]
After running:
g++ --std=c++11 -ansi -pedantic-errors -Wall -o test_database test_database.cpp
I am receiving the following errors:
./database.h:40:10: error: 'auto' type specifier is a C++11 ...
0
votes
1
answer
58
views
Execution speed of code with `function` object as compared to using template functions
I know that std::function is implemented with the type erasure idiom. Type erasure is a handy technique, but as a drawback it needs to store on the heap a register (some kind of array) of the ...
0
votes
0
answers
20
views
it's not reaching end of file while reading the file and loop runs for infinite [duplicate]
while loop in ifstream
does not stop
even if the the condition is to stop at the end of file
also i intended to read the string till it reach either full stop or max 75 character limit for a line
then ...
0
votes
3
answers
112
views
C++11 delay the execution of thread
I'd like to create some threads (with c++11) and collect them in a 'vector'. Then I'd like to fire them up, not immediately upon construction of the associated thread object, but after a specified ...
-1
votes
0
answers
22
views
jpeg_dynamic_io/png_dynamic_io in Boost depreciated
#include <boost/gil/extension/io/jpeg_dynamic_io.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
Is the header file depreciated in boost
fatal error C1083: Cannot open include ...
0
votes
0
answers
43
views
Why isn't the user-defined copy constructor invoked? [duplicate]
See the code in http://cpp.sh/8bsdl:
// copy constructor: deep copy
#include <iostream>
#include <string>
using namespace std;
class Example5 {
string* ptr;
public:
Example5 (...
0
votes
1
answer
20
views
How to store c++ structures with __attribute__((packed)) in MySQL database?
How can I easily store and retrieve c++ structures of any size with attribute((packed)) in MySQL DB?
Structure example:
typedef struct __attribute__((packed))
{
signed char result;
unsigned ...
0
votes
0
answers
18
views
"TBB library cannot be found" CMake on MacOS
I'm trying to build PrusaSlicer from source on Mac. I don't have any experience with CMake. I'm following the instructions given here.
Every time I try to build dependencies. This command cmake .....
0
votes
2
answers
65
views
Can `#ifdef` be used inside a macro?
I only found this related question, which isn't quite what I am looking for.
I used to have macros defined inside an #ifdef statement:
#ifdef DEBUG
# define PRINT_IF_DEBUGGING(format) printf(format);...
1
vote
0
answers
17
views
openssl/conf.h file not found error on MacOS
When trying to compile code (using cmake), I keep getting this error :
In file included from /usr/local/include/cpprest/http_client.h:68:
In file included from /usr/local/include/boost/asio/ssl.hpp:18:...
0
votes
0
answers
32
views
class selector from input file
I would like to have a class selector to warn the user of what classes are available of a certain type.
I have the following example code:
#include <iostream>
#include <string>
#include &...
0
votes
1
answer
64
views
How to get out of "std::thread::id" the same id as the "WinAPI thread-id" (on Windows)?
How to get out of std::thread::id the same id as the "Win API thread-id" (on Windows)?
The thread-id is 9120 (id and this_id). I tried a few ANSI C++ ways, but they resulted in a different ...
-2
votes
0
answers
42
views
when data in shared_ptr is deleted [closed]
im trying to use shared pointers in a program that uses an avlTree that i wrote ,
when i use valgrind i see a lot of errors like this :
==113447== Invalid read of size 4
==113447== at 0x40169C: ...
0
votes
0
answers
44
views
unique_ptr in c++11 : compiling on mac but not on linux [closed]
I have a school project in C++. I'm currently on mac and have no problem compiling my code when typing 'make' in the terminal. However, when I switch to the virtual machine of my course, which is in ...
-1
votes
1
answer
47
views
getline unreliable on macOS?
as a school project I have to code a video game with SDL2, imgui and SFML and I'm facing a really weird problem :
getline seems unreliable on macOS but not on linux
Let me explain, when I compile and ...
-1
votes
1
answer
43
views
Why is my code to detect a cycle in a graph not printing anything?
I have written the code to check if a cycle exists or not in a graph using breadth-first traversal.
If I declare the adjacency list as vectoradj[n]; then it's okay.
But the problem arises when I use ...
-2
votes
0
answers
47
views
Cout the unique values on console stored in single variable
I am new in C++. This is my program, which is generating a random number from 1 to 270:
#include <iostream>
#include <ctime>
#include <cstdlib>
void myFuncB(int par)
{
std::cout ...
2
votes
2
answers
63
views
Problem with a junk value in a member when using an empty default constructor
I am trying to create a very basic class with a default constructor:
class Point {
public:
Point() = default;//con 1
explicit Point(double x): x_axis(x), y_axis(0){}//con 2
...
0
votes
1
answer
53
views
Why doesn’t `std::make_shared` work anymore when the class inherits class `enable_shared_from_this`? [duplicate]
Why doesn’t std::make_shared work anymore when the class Widget inherits class enable_shared_from_this?
Here is the code snippet:
#include<memory>
#include<vector>
#include<iostream>
...
1
vote
2
answers
49
views
Question about operator==( const std::shared_ptr& lhs, const std::shared_ptr& rhs )
As per the document, which says that:
template < class T, class U >
bool operator==( const
std::shared_ptr<T>& lhs, const std::shared_ptr<U>& rhs ) noexcept;
It indicates ...
-3
votes
0
answers
27
views
Can we write a GTEST case in C++ which reads JSON from a file and update in std::map to test idividual field s inside JSON? [closed]
A JSON Sample
{
"steps": [
"applicability"
],
"arch": "xxyy",
"num_cu": 56,
"config_tuna_id": 1,
"config": {
&...
0
votes
1
answer
25
views
Why am I getting this error in the Graph Coloring problem? [duplicate]
I have written this code:
Can someone tell me what the mistake am making?
It's telling me that warning: taking sizeof array of runtime bound [-Wvla]
#include <bits/stdc++.h>
using namespace std;
...
0
votes
1
answer
45
views
Function template in header: implicit instantiation duplicated or shared?
Following function template is defined in Foo.h.
#include <array>
using namespace std;
template<unsigned N>
array<int, N> gen_arr() {
array<int, N> arr = {0};
return arr;
}...
0
votes
0
answers
23
views
Changing function in an object's member
I am trying to write a very simple game using C++ and SDL2. I have a gameObject class and a player object. I am trying to change the update function for the player member only. This is because in the ...
0
votes
0
answers
8
views
MacOS undefined symbols for architecture arm64 VSCODE [duplicate]
I tried tu running a c++ code with this command on the terminal
g++ --std=c++11 Main.cpp Heap.cpp -o Heap
But the terminal shows this, and I don't know what to do to correct this problem. Have you an ...
1
vote
0
answers
21
views
Is waiting for action completion in MQTT async_client necessary?
I am working on an cpp MQTT async_client utilizing the paho library. I am trying to fully understand the workings of the asynchronous client, but I am not sure how to correctly utilize the features.
...
-1
votes
0
answers
44
views
Object not declared in this scope error in cpp?
I'm getting error
SPIGtestMain.cpp:"MockObj not declared in this scope"
though I've declared it globally in with extern keyword in SPIGtestMain.cpp file.
SPIGtestMain.cpp
#include "...
1
vote
0
answers
41
views
Member specialization does not match any template declaration
The code below compiles except for the lines
template <> std::map<std::string, std::function<Goo*(Foo*)>>& Factory::getMap<Goo, Foo*>() {
return gooMap;
}
What is ...
0
votes
1
answer
23
views
How to find the count of sub numbers of size k which divide the number
Given a number n
Find the count of the sub numbers of size x in a number num which divides num.
For example, if the number is 250
and x=2
the answer will be 2
as 250%25==0
and 250 % 50==0.
Can anyone ...
-3
votes
0
answers
25
views
How to create a graph in C++? [closed]
I am trying to create a graph and print it using an adjacency list in CPP but it is saying that the adjacency list is not declared. What is the mistake I am making over here in this code?
p.s: I want ...
2
votes
2
answers
64
views
Defining an atomic<> as a static variable inside a function
C++11 mandates that static variables inside a function are atomically initialized for the first run of the function. The only way to do that efficiently is double-checked locking to prevent an ...
-2
votes
0
answers
35
views
Identifier "Return" is undefined in gtest?
SPIGtestMain.cpp
#include "gtest/gtest.h"
#include "gmock/gmock.h"
TEST_F(GivenANewSPI,WhenDemoIsCalled_TheComponentGetsVal)
{
unsigned char const *Ptr;
unsigned char ...
0
votes
1
answer
38
views
Question about the declaration about the aliasing constructor for `std::shared_ptr`
I think the 8th constructor of the std::shared_ptr<T> should be decalared as
template< class T, class Y >
shared_ptr<T>( const shared_ptr<Y>& r, element_type* ptr ) ...
1
vote
1
answer
47
views
BOOST request sending JSON data
I want to transfer json data into request of json boost in cpp.
If i take json in boost
int outer=2;
value data = {
{"dia",outer},
{"sleep_time_in_s",0.1}
};
...
-3
votes
1
answer
33
views
I need a function to delete certain characters from a char array in c++ without using any index
for example:
if the user enters :
( 23+22+43)
I want the function to do exactly the following :
for(int i =0; i <strlen(x);i ++)
{
if (x[i]=='+')
{
deletfunc(x[i]);
deletfunc(x[i+1])...
0
votes
0
answers
15
views
program compilation c++11 extension error in c++
I am using Vscode to compile my c++ programs. I have a program in which auto keyword is used. However when I compile it gives me the error. I have installed c++11 extension pack . But I am not able to ...
0
votes
2
answers
51
views
Different values for integer
Trying to insert values of square and cube of a number in set st and st1. (Let n = 10^7).
After printing, set st is having negative values due to limit of integer but there are no negative values in ...
0
votes
1
answer
53
views
How to create a simple version of std::function class
Suppose that I want to create a simple version ofstd::function, which has following behaviors:
1. function(){} -> A void constructor
2. function(_ReturnType, Args... vlist) -> To convert ...
-1
votes
1
answer
39
views
How to save/load values from board to file
Im using c++ 11,
I need to save/load array to and from file. Its the battleship game its need to be done for both user and computer array but i have no idea how to start with this task.
I want to use ...
0
votes
0
answers
30
views
What are the best practices and coding guidelines for pointers and memory management in C++? [closed]
To write code efficiently, what are the best practices and coding guidelines need to be followed for pointers and memory management in C++?
Thanks,
0
votes
1
answer
76
views
Making the nodes of an unordered_map or map<> cacheline-aligned
How can I make the nodes and the bucket-"list" of an unordered map cacheline-aligned to avoid false sharing with other data structures on the heap ?
2
votes
3
answers
41
views
How to allow a user to enter one or two inputs?
Say you wanted a user to enter a base for a root, and another number for the root. But, if the user only provides 1 number, the 2nd input will default to 2, so a square root.
I want to know how to ...
0
votes
0
answers
32
views
Find Four Elements That Sums To A Given Value : Wrong Output
I am trying to solve the question,
Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:
0 <= a, b, c, d < n
a, b, c, ...
1
vote
1
answer
38
views
Calling templated member-pointer through templated class-object
Why does this not work ?
#include <type_traits>
#include <utility>
#include <string>
using namespace std;
template<typename C, typename ... Args>
void callMember( void (C::*...
0
votes
1
answer
48
views
error: invalid cast from type ‘void (*)(int)’ {aka ‘void (*)(int)’} to type ‘void’
void* l = dlsym(lib,"_ZN11Environment9LibLogger14log_processingEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjS6_z");
void (*log_fcn)(int level, std::string format, unsigned int ...
3
votes
1
answer
51
views
What will happen if I pass a mutable lambda to a function as const reference?
What does the code actually do when I pass a mutable lambda as const reference?
Why does not the compiler raise error, is this an undefined operation?
Why f1 and f2 are differnt which f1 uses std::...
-2
votes
0
answers
29
views
how to use function variables inside a lambda in C++ [duplicate]
Here in C++, i want to use a variable invalidNumber which is already available in a function scope inside the lambda. There was a compiler error when i tried the below code. How to make Lambda ...