Category : c++

Given a function which returns a heavy-to-construct and heavy-to-destroy object, is there a way to skip object construction and destruction if the function return value is not consumed? HeavyObject func(); auto res = func(); // heavy object is constructed and returned func(); // lightweight "null" object is returned and immediately destroyed Is there a technique ..

Read more

I am trying to use a C++ object in Python that has in argument a cv::Mat. Here is my code : //simplelib.h #ifdef SIMPLELIB_EXPORTS #define SIMPLELIB_API __declspec(dllexport) #else #define SIMPLELIB_API __declspec(dllimport) #endif #ifdef _DEBUG #undef _DEBUG #include <Python.h> #include <boost/python.hpp> class simplelib { private: cv::Mat input; public: /*Constructor for the simplelib class*/ SIMPLELIB_API simplelib(cv::Mat input); ..

Read more

I am trying to integrate rabbitmq into one of the modules of my solution in order to switch from mailslots to rabbitmq. The problem is that during the fectcontent, the module "breaks" the links of the other modules. The errors generated are "unresolved external symbols". ########################## # CODE CMAKELISTS ########################## file(GLOB sources "src/*.cpp" "src/*.c") file(GLOB ..

Read more

I am trying to calculate how many males and females from data obtained from a file. But when i placed struct pneumonia { string gender; }patientInfo[3]; //inside main func ifstream p("patient.txt"); for (int i=0;i<3;i++) { getline(p,patientInfo[i].gender,’;’); } int tm=0, tf=0; for (int i=0;i<3;i++) { if (patientInfo[i].gender == "female") tf++; else tm++; } cout<<"Male :"<<tm<<"nFemale :"<<tf<<endl; ..

Read more

I got this example from cpp reference: https://en.cppreference.com/w/cpp/algorithm/find: std::vector<int> v{1, 2, 3, 4}; auto result2 = std::find(begin(v), end(v), 2); My first intent would have to be that both arguments begin(v) and end(v) must have the namespace specifier prefixed: std::begin(v) and std::end(v). But apparently according to the example it is also possible to leave this out. ..

Read more

#include <iostream> float calculating_root(float N, float root_N, float increment) { int safety=1; while(safety==1) { if (N == (root_N*root_N)) { safety=0; return root_N; } else if(N<((root_N+increment)*(root_N+increment))) { safety=0; return calculating_root(N,root_N, increment*0.1); } root_N=root_N+increment; } } int main() { float N, root_N=0.0, increment=1000.0; scanf("%f",&N); float x = calculating_root(N, root_N, increment); printf("n%gn",x); return 0; } I’ve been thinking ..

Read more

The code shows an invalid conversion from int to *int how do I fix the problem … the full detail of error is given below : Code: #include <iostream> using namespace std; bool isSafe(int** arr[], int x, int y, int n) { if (x > n && y > n && arr[x][y] == 1) { ..

Read more