Questions tagged [c++11]

C++11 is the version of C++ after C++03. This tag should be used (along with the [C++] tag) for questions about C++ features specific to C++11.

c++11
Filter by
Sorted by
Tagged with
0 votes
1 answer
852 views

SDL2 loading files with special characters

I got a problem, that is: in a Windows application using SDL2 & SDL2_Image, it opens image files, for later saving them with modifications on the image data. When it opens an image without special ...
Platón_actual's user avatar
-1 votes
2 answers
548 views

How prevent errors on windows when i use Qt Android Extras C++ Classes

I used the solution of below question for open file on Android. Qt/Necessitas - reasonable QFileDialog replacement/skin? But it works just on android,this codes (Qt Android Extras C++ Classes) don't ...
mohsen's user avatar
  • 1,823
11 votes
1 answer
242 views

Why is std::initializer_list conversion not preferred?

Consider this snippet: #include <iostream> #include <vector> void f(std::vector<int>){std::cout << __PRETTY_FUNCTION__ << '\n';} void f(int x){std::cout << ...
vsoftco's user avatar
  • 56.1k
1 vote
2 answers
1k views

How does function overloading work when passing NULL as argument?

I know that NULL is #defined to be 0. It seems to be an int constant that gets converted to a pointer type. So what happens when there are two overloaded functions: one takes a pointer type, another ...
Galaxy's user avatar
  • 2,461
1 vote
3 answers
102 views

Struct's pointer and how to access elements

i wanted to create a little example for struct's witch constructor and destructor, but my problem is that i can't "print" Zahlen[0] and i don't know why? Thank for any kind of help. Maybe i have to ...
vanderub's user avatar
13 votes
1 answer
2k views

std::regex and dual ABI

Today I have found an interesting case of the dual libstdc++ ABI affecting compatibility of libraries. Long story short, I have two libraries that both use std::regex internally. One is built with ...
n. m. could be an AI's user avatar
2 votes
1 answer
168 views

g++-floating point behavior with -O option not strictly C++11-standard conformal?

Consider int main() { double d = 1.0e+308; std::cout << (d*d)/1.0e+308; } compiled with g++ version 4.8.5 and the two compiler options -std=c++11 and -mfpmath=387 on a Linux CentOS ...
Teilhart's user avatar
  • 119
3 votes
2 answers
153 views

User-Defined Conversion Operator Ignored for Class Template (Not So for Non-templates)

This code does compile (the important point is that F() only accepts As, and since there is an implicit conversion from B to A, I can easily pass a B to it.) struct A {}; struct B { constexpr ...
yzt's user avatar
  • 9,023
4 votes
4 answers
688 views

Parameter packs with specialization for one data type

I have below code to convert all arguments passed to a function into csv: void Parse(ostream& os) { } template <typename T, typename... Args> void Parse(ostream& os, T t, Args... args) ...
ARaj's user avatar
  • 41
-3 votes
1 answer
89 views

How to find element kth in array?

For array A={2, 5, 5, 8, 10, 10, 13, 13,...}, (A={1^2+1^2, 1^2+2^2, 2^2+1^2, 2^2+2^2, 1^2+3^2, 3^2+1^2, 2^2+3^2, 3^2+2^2,...}) and number K (K<=10^12). Find kth element in array. I cannot ...
Nguyễn Văn's user avatar
2 votes
4 answers
2k views

How to get exactly one element from an unordered_set?

I have: std::unordered_set<ObjectRepresentation*> incompletePieces; I would like to get exactly one object from the unordered_set. To do that I am using a for loop, and "break", at the ...
Rahul Iyer's user avatar
  • 20.4k
1 vote
0 answers
47 views

Prevent specifying each integral value as unsigned in array-initializer

Consider the following function which takes a reference to an array of a size N deduced at compile time: template <size_t N> void array_consumer(unsigned const (&source)[N]) { // ... } I ...
BeeOnRope's user avatar
  • 62.5k
1 vote
1 answer
91 views

Difference between 'new' and '=' in relation to pointers

These two pieces of code are creating very different results depending on the compiler and I don't understand why node *active_node = new node; vs node current_node; node *active_node; active_node =...
ARNAV RAMKRISHNAN's user avatar
-3 votes
1 answer
598 views

C++ String comparison with same size and content returns false [closed]

I'm having a problem when I'm trying to compare a string resulted from a function, with a string that is manually declared: string ip = "3.3.333.33"; string cuxa(){ HINTERNET hInternet, hFile; ...
an4rei's user avatar
  • 57
0 votes
0 answers
59 views

Find kth smallest element in matrix

I have problem/assignment about finding the k-th smallest element in a matrix. I have a matrix A(NxN), with Aij = i* i + j* j and N = 10^6. The upper time limit is 1sec, using C++ 11 in Visual Studio ...
Nguyễn Văn's user avatar
-1 votes
1 answer
214 views

C++ - Need to read the timestamps stored in file(.txt) and retrieve the same properly

I have a scenario to store five different date and time stamps in a file (.txt) and retrieve the same and map it to different variables for processing. For example I have the following data's which ...
KMN's user avatar
  • 1
5 votes
2 answers
288 views

C++11: 'decltype class instance declaration' with std::move( ) doesn't call 'move constructor.' Why?

I recently started using c++ and I chose to learn c++11 features. But how c++ codes run is sometimes not so tangible. below is my code. At the part with decltype(std::move(sample)) sample2 = std::...
Kiseong Yoo's user avatar
-1 votes
1 answer
1k views

JSON Object to C++ model

I want to "convert" a JSON Object to C++ model. Let's say I have this simple JSON: nodes:[ {text: "Node1"}, {text: "Node2", nodes:[ {text: "Node 2-1"} ] } ] In C++ I have this ...
marissalianam's user avatar
0 votes
2 answers
855 views

C++: outFile error: outFile was not declared? [closed]

This is the code: { //Open and write to (virtual) memory if (memory) ofstream outFile; const char *outputFileName = ("memory.txt"); outFile.open(outputFileName, ios::out); outFile&...
Gh0stwarr10r's user avatar
0 votes
2 answers
1k views

unpack variadic template parameters

I have a template function: template<typename R, typename... T> void function(const std::string& id, R (*f)(T...)) { switch (sizeof...(T)) { case 0: f0compile<R>(...
Mario Rollino's user avatar
2 votes
4 answers
1k views

How do I print the sum of first and last elements, followed by the sum of the second and second-to-last, and so on?

Im very new to programming, and am working through the C++ Primer 5th edition. One of the exercises requires me to enter a set of integers into a vector and print the sum of the first and last ...
Dan's user avatar
  • 23
0 votes
2 answers
372 views

Infinite loop when using exceptions in c++11

I would like to create a c++11 program that takes in 10 positive integers and gives the user the total. In the event of a negative number or a char input, the exception should be thrown and the user ...
Noob_Programmer's user avatar
4 votes
2 answers
554 views

Need help decoding this typedef

I'm trying to create a reference to an array. It works this way: typedef int array_type[100]; int main() { int a[100]; array_type &e = a; // This works } But then I was trying to ...
Vishal's user avatar
  • 3,226
5 votes
3 answers
2k views

Why can't I use std::unique_ptr as a "template<class> class" argument?

This code: #include <memory> template <template <typename> class Ptr> class A { Ptr<int> ints; }; using B = A<std::unique_ptr>; yields the following error (with GCC 6....
einpoklum's user avatar
  • 124k
3 votes
3 answers
77 views

Avoid Conversion from single element vector to primitive type

I have a problem with constant single element std::vector when pass through a function. C++ compiler automatically call wrong function when the std::vector variable contain a single element. This is ...
MooMoo's user avatar
  • 1,116
0 votes
1 answer
192 views

Create a string from c++11 time_t that is convertable to .net DateTime

This is a follow up question to this question: Standard conformant way of converting std::time_t to System::DateTime? I need to convert a c++11 time_t to .NET DateTime by a string. The program needs ...
CodeMonkey's user avatar
  • 11.8k
4 votes
1 answer
880 views

C++ attributes namespace?

Cppreference says the attribute-list inside the double brackets [[ ]] can be identifiers. Say I have a variable named noreturn in my C++ program (so it is an identifier of a variable). Does it ...
Leedehai's user avatar
  • 3,840
12 votes
2 answers
3k views

array vs std::initializer_list as function parameter

I can write a function which take a temporary array(such as {1, 2, 3}) as an argument in two ways: // using array template<typename T, int N> auto foo1(const T(&t)[N]) -> void; // using ...
slyx's user avatar
  • 2,165
2 votes
2 answers
815 views

Swapping mutex locks

I'm having trouble with properly "swapping" locks. Consider this situation: bool HidDevice::wait(const std::function<bool(const Info&)>& predicate) { /* A method scoped lock. */ ...
FrogTheFrog's user avatar
  • 1,559
2 votes
1 answer
85 views

Define class with fields from the type of the class

Can someone explain me why I can't define something like that: Class A { A a; //... }; But I can define something like that: Class A { std::vector<A> vec; //... }; What is the ...
Software_t's user avatar
-1 votes
1 answer
193 views

why map emplace calling rvalue constructor twice

class twoMem { int _a; int _b; public: twoMem() { std::cout << "default constructor" << std::endl; } twoMem(int a, int b) :_a(a), _b(b) { std::...
devdy's user avatar
  • 9
-1 votes
1 answer
799 views

How can I fix these errors? "redefinition of 'template std::ostream& operator<<" , "unresolved overloaded function type"

Given the following code: #ifndef MATRIX_H_ #define MATRIX_H_ #include <iostream> #include <vector> using std::ostream; using std::vector; using std::string; class BadDims: public ...
Software_t's user avatar
0 votes
1 answer
73 views

Error with definition of "(abstract) exception class" with function "what()"

Given the following classes: #include <iostream> using std::ostream; class MatrixException: public std::exception { public: virtual ~MatrixException() { } virtual const char* what(...
Software_t's user avatar
1 vote
2 answers
167 views

search for insert position using c++11 range-based-for-loop

I wonder weather it is possible to use the the c++11 ranged-based-for-loop syntax to search for an insertion point that is later used in i.e. a list. Can I compact the for (auto i = l.begin(); i != l....
Konrad Eisele's user avatar
0 votes
1 answer
115 views

C++ book-keeping of all instantiations of a class template

In my API I have a class template template<class T> struct MyType. The user of my API can instantiate the template MyType with several types (e.g. MyType<int>, MyType<UserType>, ...
Kilian's user avatar
  • 543
0 votes
1 answer
54 views

access a templatized nested class function and object in another class

I have two header files. one of the header files is tree.h which has a templatized class. It contains another class of "iterator" as well. template <typename Key, typename Value> class tree ...
SunAns's user avatar
  • 303
2 votes
1 answer
2k views

How to call move constructor?

I have the following code: #include<iostream> using namespace std; class A{ int size; double *arr; public: A(int len):size(len) { cout<<"ctor called"<<endl; ...
aalisha's user avatar
  • 41
5 votes
0 answers
221 views

How does this non-type template parameter expansion work? + Possible bug in gcc? [duplicate]

template <typename T, typename T::tag...> void f() {} struct Tagged { using tag = struct{}; }; struct Untagged {}; void test() { f<Tagged>(); f<Untagged>(); // fails } ...
Vladislavs Burakovs's user avatar
0 votes
2 answers
92 views

Strategy to omit unused boost src files while shipping source code

I'm using #include <boost/numeric/ublas/matrix.hpp> in fact that's the only boost file I've included. Now I want to ship the source code and I was hoping not have to include all hundreds of ...
KcFnMi's user avatar
  • 5,961
0 votes
0 answers
151 views

Why Copy Constructor not called?

I have the following piece of code: #include<iostream> using namespace std; class A{ int size; double *arr; public: A(int len):size(len) { cout<<"ctor called"<&...
aalisha's user avatar
  • 41
0 votes
0 answers
57 views

How does a C++ Pointer really Treat Character Array and Integer/other datatype arrays?

#include<iostream> using namespace std; int main() { char x[]{"GOD BLESS!"}; char *ptr = x; // char *ptr{&x[0]}; cout<<endl<<"Value of ptr is: "<<ptr; // ...
Electro Voyager's user avatar
2 votes
1 answer
144 views

Which C constructs appear in the std namespace?

The recommended way to include the C standard library header <foo.h> in C++ is to include the corresponding C++ header <cfoo>. Based on my experience this puts some of of the ...
BeeOnRope's user avatar
  • 62.5k
3 votes
1 answer
69 views

why conversion operator is getting called when std::for_each() returns?

I am learning functors and their usages. I came across below code in one of stack overflow questions. #include <iostream> #include <algorithm> #include <vector> using namespace std;...
kadina's user avatar
  • 5,170
2 votes
2 answers
121 views

How to write a variadic function without parameter pack?

suppose I have a template template<typename Bar> Result foo(const Input& input); and I instead want to create a template foo() that would get many Bar template arguments and many Input's ...
user44168's user avatar
  • 425
4 votes
1 answer
446 views

Strange shared_ptr comparator selection for priority queue in GCC

I have a class wrapped in std::shared_ptr, and I want to select top-k objects with help of std::priority_queue. So, I define operator < and expect that everything will be fine. But it is not true. ...
r3t's user avatar
  • 53
0 votes
1 answer
50 views

Order of evaluation of functions used as parameters to member constructors

Let's assume a class: struct S { Obj1 o1; Obj2 o2; S() : o2( fn2() ), o1( fn1(), fn3() ) {} }; What is guaranteed to be sequenced-before in this case? o1() is sequenced-before o2(). ...
Andre Kostur's user avatar
0 votes
0 answers
125 views

Eclipse can't understand boost and smart pointers?

We're using Eclipse CDT for C++ 11 code. I have a class I need to refactor so it can be tested. We're using Google Test/Google Mock to write our unit tests. One class contains a Boost socket, like ...
Frecklefoot's user avatar
  • 1,690
10 votes
0 answers
70 views

Type deduction in switch and SFINAE, gcc vs clang [duplicate]

I've noticed a difference in behavior between Clang and GCC with following code: class convertible { public: operator int() { return 1; } template <typename T> operator T() { ...
random's user avatar
  • 3,938
0 votes
1 answer
67 views

C++11 rvalue reference addressing

I'm trying to understand the c++11 move semantics, and created the following sandbox project: main.cpp #include "my-class.h" #include <iostream> MyOtherClass getRValue(void) { MyOtherClass ...
corsel's user avatar
  • 315
-1 votes
1 answer
32 views

Replace 8 characters after finding 3 characters from a string

Is it possible in C++ to replace 8 characters after finding 3 characters from a string I tried below Input: txtvar = "This is for Testing Purpose line"; Expected should be output txtvar = "This ...
Sam's user avatar
  • 1

1
259 260
261
262 263
1134