Category : arguments

I’ve been working on a problem in which I need to pass a multidimensional array to a function, specifically 2D array. In C++ although, I’m using the correct syntax, the compiler complains errors that says, My code: void traverseArraySpirally(int rows, int columns, int array[][columns]) { int top_row{}, bottom_row{rows-1}; int left_column{}, right_column{columns-1}; int i{}; while(top_row <= ..

Read more

I have a function that is something like this: void OpenPattern(std::string filename, bool type){ Mat img = cv::imread(filename, cv::IMREAD_COLOR); if(img.empty()){ printf("CANNOT OPEN IMAGE"); }else{ doSomethingElse(); } } the code compiles alright, but when I run it, img is always empty. I’ve tested filename storing a relative path and a full path to the image. Neither ..

Read more

here is the question: Using default arguments, write a function that asks the user for a number and returns that number. The function should accept a string prompt from the calling code. If the caller doesn’t supply a string for the prompt, the function should use a generic prompt. Next, using function overloading, write a ..

Read more

I have this code which is working without anny issue: void function_exit(dispatcher& d) { /* .. */ } // … std::thread th(function_exit, std::ref(main_disp)); th.detach(); now I tried create another class which hold std::thread which produce errors on compilation thread_control mtc; mtc.create<dispatcher&>(function_exit, main_disp); here is create function: (please read a comented text for describing a problem) ..

Read more

I have a question because it is not clear to me when function arguments get destroyed. Therefore, is the concatenation of the following doSomething function error-prone or not? I’m asking because "it is the programmer’s responsibility to ensure that std::string_view does not outlive the pointed-to character array". Can that be guaranteed in that specific case ..

Read more

Say I have something like this template<typename T1, typename T2> struct my_struct { using type = typename T1<T2>::type; }; where I know for sure that T1 is a type trait (such as remove_const, is_floating_point, etc). Then in the main function I want to be able to write using test = typename my_struct<is_integral<>, float>::type; where test ..

Read more