Newest 'c++11' Questions

Q&A for professional and enthusiast programmers

Using methods with a Template

I am quite new to C++ and so was wondering if you guys could help me. I was going through a piece of code and saw a function underneath a template, like this: MyClass(xyzType param1, xyzType param2) ...

How to Change LLDB Version CLion Uses?

TL;DR: I want to change the version of LLDB that CLion (v2016.3.5) uses to LLDB v3.8.1. Can I do this? If so, how? Longer explanation of the question: CLion is a C++ IDE that I've been using for a ...

recursive function not called properly

I'm using a recursive method to convert a number into a representation in base of 7. However, after I run the program, the output string is identical to the input number. What's cause that the ...

A C++ templated function issue

I have a problem with a Template function inside a class. When I call "Set" in something() function, VS show me: Error C2275 'T': illegal use of this type as an expression The header is: #...

parsing CSV file then grab data using function [duplicate]

hello I'm needing help with parsing data from a CSV file the data is as followed make,model,year,milage,cost chevy,Silverado,2009,15,20000 ford,mustang,2017,25,35000 once I do this I have some get ...

Overloading virtual << operator c++

I have the following code in io.h: #include <iostream> #include "shape.h" class IODevice { // Interface for displaying CAD objects public: virtual void operator << (const ...

Are moves automatically used when reassigning to the mapped variable?

Suppose I implement a new interface for sort vector<int> sort(vector<int> in){ //sorting logic } And use it like this vector<int> some_integers = {2, 1, 3}; some_integers = sort(...

errors linking clang-built executable with g++-v6-built boost library

I have a boost regex library built myself with g++ version 6.3.1 on Fedora Linux. Then I have my own library using the boost regex, built with clang++ 4.0 as shared object. Building this works fine. ...

Cant Use my function that i 've created in Header file [on hold]

I'm trying to use my function that i've created previously in Main.cpp and then i came up with the idea to include my function to my own header file named center.h . i'm not sure why i cant called my ...

What is the difference between the two wording when the two-dimensional array is a function parameter?

What is the difference between the two wording when the two-dimensional array is a function parameter? #include <bits/stdc++.h> #include <windows.h> using namespace std; void dfs(...

Is it possible to create a “perfect forwarding” generic collection in C#?

Consider this C++ code snippet: std::vector<Foo> bar; bar.emplace_back(9001); //Foo defines a constructor that takes int This will create an object of type Foo, pass-through any constructor ...

My code crash with the following message “Thread 1:: EXC_BAD_ACCESS(code=1,address=0x8)”

Im new on c++ and recently, found myself trying to understand why the code above, compile and run, but suddenly after enter the first grade crash, I figgure out that the problem was when i try to use"...

why use the underlying type of an enum class to define a variable?

I saw the following comment in some code. * The implementation uses custom pointer types to save space, and * to preserve addresses if the underlying container is resized. * For instance we define ...

Address of address of a array

The following code on execution gives output as '6'. #include<stdio.h> int main() { int a[]={7,5,3,4,1,6}; int *ptr=(int*)(&a+1); printf("%d",*(ptr-1)); ...

How to accomplish C++11 compile time class static member initialization on a bitset?

I'm attempting to do the following: Say I have a class, A, and I have a static member variable, static_bit_id, that is a bitset<128>. At compile time, I want to create an ID that is a one hot bit ...

Vector type String but when initialize with integer

I have below code: vector<string> v6{10}; cout << v6.size() << endl; for (int i = 0; i < 10; i++){ cout << v6[i] << endl; } Output is in the below picture: ...

Distinguishing by parameters with function templates and SFINAE

I'm breaking sweat over disecting function templates to three groups: one to produce functions that take integrals, one to take floating points and one to take any other (that ostringstream::<< ...

Can using be used to type alias an array?

I'm not sure I've worded this properly since this is a bit of an odd situation. Basically I've found some code like this: template<class T> struct X { typedef T Type; }; template<class T>...

writing a map of structures to xml using boost

i could successfully write a map < string, struct values > to xml file using boost serialization but while i tried writing a map < int , map < string, struct values > > to xml file ...

Converting from sub_match<const char *>' to 'const char *const &'

I am trying to map std::match_results data to my std::multimap variable. Here's the code: #include "Precompiled.h" using namespace std; using namespace tdd; auto main() -> int { auto ...

Define methods in template class in c++

I am making a template class which has variable template arguments. However, when I define and call a method, my compiler says the method is not defined. template <class T, class... Args> class ...

Can't include the JPEG_SUPPORT headers in a dlib cpp file

I was trying to compile a cpp file: the face-finder in dlib: http://dlib.net/face_detection_ex.cpp.html. But when I ran it, it said I had to include the libraries for jpg and png files: processing ...

C++11 - Unicode string - find if contains non-ascii based characters

I have Unicode string in C++11 represented in UTF8 class. I can get Unicode character numbers. How can I check, if the string contains characters, that are not ASCII based (with diacritics)? Eg. I ...

Invalid use of non-static data member from within a nested class

I'm writing some code with polymorphic inheritance of two classes from a base class all nested within a class like this: #include <iostream> using namespace std; class A { class base ...

Why I can't assign , &client object created by new to unique_ptr

I know there are other ways to do this. But I decide to experiment this: unique_ptr<int> pi; pi = std::move(new int); When I compile this code, the compiler gives an error. why?

Create a distinct matrix with random numbers between 1 to 75

I tried to create a matrix of random numbers ranging from 1 to 75 for a bingo game. But, I am not able to generate distinct numbers. The first row should have no from 1 to 15, second row from 16 to ...

Can inheritance be used to reduce the size of compiled code in C++?

I am working on a project for an Arduino-based sytem (i.e. an embedded system) and have a limited amount of ROM for code to live in. I have found myself needing several different types of collection ...

Enable one operator() based on the dimension

I'd like to create a form class that, based on its template arguments, provides one operator() with one or more parameters. This is a prototype for curves, for example linear, bilinear, and so on. So,...

Printing either to console or to a string/stream

I need a C++ function that dumps some text data (multiple lines) to the console: void DumpData() const { std::cout << "My Data 1" << std::endl; std::cout << "My Data 2" <&...

Is it better to include <cassert> or <assert.h>? [duplicate]

Using C++11, is it better to #include <cassert> or <assert.h>? Or is there no difference?

condition variables c++ windows

I am trying to run some code copied from Windows Dev Center, but keep encountering an error over some unresolved identifiers. This maybe sound silly, but why would these lines cause this error: ...

Set current user environment variable from c++ code visible to other process like cmds

I need to set a local environment variable for current user and it shoukd be visible to other processes like a new command prompt. I need it for windows. I have tried options like putenv and editing ...

collect2.exe: error: 1d returned 1 exits status

I am coding in c++ on SublimeText3 and using the command window in the folder to manually compile it and run it but when i try compile it using g++ -Wall -pedanntic -std=c++1 TheThirdTask.cpp -o ...

“adjacent_find could not be resolved” error

I'm trying to use adjacent_find in C++ as part of a maximum algorithm, but I'm not exactly succeeding. It worked in Xcode, mainly because it uses a different compiler. Now, I'm in Eclipse on a ...

Is there any type trait which controls member type(not member variable) [duplicate]

STL comes with many type traits like std::is_pointer, std::is_reference etc... Lets say I have a class class A { using type_member = void; } Is there any type trait for controlling the ...

Compile error when trying to use std::result_of

I want to deduce the return type of a function coming as a template parameter. Consider the following code: #include <type_traits> struct Result {}; Result foo() { return Result{}; } ...

OpenBSD eg++ 4.9.3: Enable multithreading to use std::thread: Operation not permitted

When trying to compile ansvif (a fuzzer) on OpenBSD with g++ (eg++) from the ports tree everything configures and compiles fine until I get to actually running the program in a place where it requires ...

shared_ptr<T> to const shared_ptr<const T>&

I feel confused about shared_ptr, and my main question is: does c++ create a new object (shared_ptr object) when I do the following? void Func1(const shared_ptr<T>& rhs) {} void Func2(const ...

Writing a map to xml using boost

i have writing a map to an xml file using the below code , but i can't successfully compile the code , i am actually trying to compile this on mac sierras terminal . Would you please advice what may ...

constexpr with untouched non-constexpr arguments: Who is correct, clang or gcc?

I have 4 test cases and I believe that all of them are valid: constexpr int f(int const& /*unused*/){ return 1; } void g(int const& p){ constexpr int a = f(p); // clang error, gcc ...

android NDK(CMakeLists.txt) with c++11

Hi I'm making a face landmark detection app in ANDROID VERSION. I'm using Android Studio 2.3(NDK SUPPORT) So far so good except build.gradle & CMakeLists.txt setting CMakeList.txt set(...

a slow templated factory

The code below shows a templated factory. It takes a functor-class and returns the operator()'s return-value. The functor-class below returns a simple struct which in this case is huge: ints.resize(...

Why does `reinterpret_cast` not behave as the C++ standard says? [duplicate]

At the entry of reinterpret_cast, cppref says: An expression of integral, enumeration, pointer, or pointer-to-member type can be converted to its own type.The resulting value is the same as the ...

how to split a string into lines, without breaking the words?

Let's say we have a string we wish to split the string into 5 chars long without splitting individual words: I am going to CUET Now if we can split this in the following way: I am going to CUET I ...

Why does C++ not allow a parameter to be a default argument? [duplicate]

void g(int n, decltype(n) = 0); // ok void f(int n, int = n); // error : default argument references parameter 'n' int main() { f(1); // want it to be same as f(1, 1); } Why does C++ not allow a ...

Using part of enum as array index

I have large enum for example: enum { elem0, elem1, elem2, elem3 ...... elem1000 } I would like to create an array of float numbers using just some of the enum elements. For example, I would like ...

c++ : confused as to why the compiler is giving error not declared in this scope

This skeleton example part of my code is causing the error 'x' not declared in this scope. I would have thought the computer would do both the Krow > 2 and Krow == 3 statements. void ...

Signal for the progressBar

Hello I would like to create a simple progress Bar with a variable j. And j could take some values I mean for instance if j = 1 the state of the progress Bar will be 10% if it is 8 it will be 80%. How ...

Regex for single match of the xml tag's content

I have a string: <tag1 qwer=123>Hello</tag1> And I want a regex that will have a single match for its inner content: Hello Using the following code: string s = "<tag1>Hello</...

How to use raw pointers recursively from unique pointers?

I am attempting to create an AVL tree with unique pointers. But I am stuck on the elementary part of inserting nodes recursively. This code creates a segmentation fault at the call to the insertNode_ ...
Translating... 0%