c++11

std::shared_ptr initialized with other shared_ptr data

跟風遠走 提交于 2021-02-11 18:12:52
问题 I'm using recently new C++11 features such as std::shared_ptr, because I am converting a C code into Classes and in this code there is an heavy usage of "old-fashioned" pointers. I have one doubt: in a method of a class, where i use local shared_ptr, can i initialized them with the data of the passed reference to another smart_ptr and then modify the data? Example: void myFunction(std::shared_ptr<T> &my_reference) { std::shared_ptr<T> my_local_ptr(my_reference.get()); /* Doing stuff on local

Accessing a std::map of std::map like an array

醉酒当歌 提交于 2021-02-11 16:55:08
问题 I have initialize a std::map of a std::map like as below: static std::map<std::string, std::map<std::string, float>> _ScalingMapFrequency = { {"mHz", {{"mHz", 1.0}}}, {"mHz", {{"Hz", 1e-3}}}, {"Hz", {{"mHz", 1e+3}}}, {"Hz", {{"Hz", 1.0}}}}; And now I am trying to access the float values in the following way: std::cout<<" the scaling factor is :"<<_ScalingMapFrequency["mHz"]["Hz"]; There is no problem when I compile and run the code but I am expecting to get "1e-3" instead I am always getting

Copy Memory to std::copy

旧街凉风 提交于 2021-02-11 16:46:00
问题 I'm trying to convert all my CopyMemory functions to std::copy functions. It works with copymemory and memcpy but not std::copy. Can anyone tell me what I'm doing wrong or how to fix it? template<typename T> void S(unsigned char* &Destination, const T &Source) { //CopyMemory(Destination, &Source, sizeof(T)); std::copy(&Source, &Source + sizeof(T), Destination); //Fails.. Destination += sizeof(T); } template<typename T> void D(T* &Destination, unsigned char* Source, size_t Size) { //CopyMemory

Copy Memory to std::copy

家住魔仙堡 提交于 2021-02-11 16:40:46
问题 I'm trying to convert all my CopyMemory functions to std::copy functions. It works with copymemory and memcpy but not std::copy. Can anyone tell me what I'm doing wrong or how to fix it? template<typename T> void S(unsigned char* &Destination, const T &Source) { //CopyMemory(Destination, &Source, sizeof(T)); std::copy(&Source, &Source + sizeof(T), Destination); //Fails.. Destination += sizeof(T); } template<typename T> void D(T* &Destination, unsigned char* Source, size_t Size) { //CopyMemory

Read comma separated integers from getline()

情到浓时终转凉″ 提交于 2021-02-11 15:37:21
问题 How can I read separate integers from the code below? while (getline(cin, line)) { // for each integer in line do something..... // myVector.push_back(each integer) } The input is like this: 1, 2, 3, 5 (separated by comma except the last integer). Sample Input (ignore the line # part): line1: 1, 2, 3, 4, 5 line2: 6, 7, 8, 9, 10 line3: 3, 3, 3, 3, 3 /// and so on... I need to read the integers one by one, and let's say increment and print them. 回答1: I make use of a handy utility to split a

Read comma separated integers from getline()

三世轮回 提交于 2021-02-11 15:34:28
问题 How can I read separate integers from the code below? while (getline(cin, line)) { // for each integer in line do something..... // myVector.push_back(each integer) } The input is like this: 1, 2, 3, 5 (separated by comma except the last integer). Sample Input (ignore the line # part): line1: 1, 2, 3, 4, 5 line2: 6, 7, 8, 9, 10 line3: 3, 3, 3, 3, 3 /// and so on... I need to read the integers one by one, and let's say increment and print them. 回答1: I make use of a handy utility to split a

How to open a dialog after QComboBox choice

让人想犯罪 __ 提交于 2021-02-11 14:50:40
问题 I have a QComboBox with several choices on a QToolBar . Every choice of the QComboBox will open a specific dialog window. The problem I have is that after I choose the preferred index on the combobox no dialogs opens up. For simplicity of the example I am linking the same dialog to all choices: dredgewindow.h This is the header file namespace Ui { class DredgeWindow; } class DredgeWindow : public QMainWindow { Q_OBJECT public: explicit DredgeWindow(QWidget *parent = nullptr); ~DredgeWindow();

cMakefile for using tesseract and opencv

别等时光非礼了梦想. 提交于 2021-02-11 14:28:12
问题 I am a newbie to cmake and I am writing an application for using tesseract. the g++ command line work fine g++ -O3 -std=c++11 `pkg-config --cflags --libs tesseract opencv` my_first.cpp -o my_first But I wrote the following CMakeFile.txt and building in Clion and it throws a bunch of linking errors cmake_minimum_required(VERSION 2.6) add_compile_options(-std=c++11) project (my_first) find_package(PkgConfig REQUIRED) pkg_check_modules (OPENCV REQUIRED opencv) link_directories(${OPENCV_LIBRARY

Is there a highly performant way to make a 56 bit integer?

删除回忆录丶 提交于 2021-02-11 14:15:10
问题 I am writing a virtual machine that has 8 bit opcodes, and one of the common types for the instructions has the 8-bit opcode, followed in memory by a 56 bit signed integer operand. Originally, I was going to implement this instruction as follows: struct machine_op { std::uint64_t opcode:8 std::int64_t operand:56; }; However, Ive heard no end of comments that using bitfields like this would not be portable, and in particular, it would not guarantee that the operand field would actually be in