« first day (913 days earlier)      last day (1946 days later) » 

7:19 AM
if i have this code:
double average {};
average = static_cast<double>(sum) / numbers.size();
why do i need to cast just the first int (sum) to a double and not the size of the vector<int>?
 
@Chris if either one is a double, then the other automatically gets promoted to double for the arithmetic.
 
cool, thx
 
 
7 hours later…
2:28 PM
I'm trying to use a function in std::thread but I can't figure out the issue:
void filterfct (cv::Mat& image, cv::Mat& grad_x, int depth,cv::Mat& kernel_x, cv::Point P)
{
cv::filter2D(image, grad_x, depth, kernel_x, P);
}
std::thread thread_1(filterfct, std::ref(image), std::ref(grad_x), CV_32F, std::ref(kernel_x), cv::Point(-1,-1));
 
1 message moved from Lounge<C++>
 
It says
/usr/include/c++/8/thread: In instantiation of ‘struct std::thread::_Invoker<std::tuple<void (*)(short int*, int, int, int), short int*, int, int, int, int> >’:
/usr/include/c++/8/thread:127:22: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(short int*, int, int, int); _Args = {short int*&, const int&, const int&, const int&, int}]’
improve_code.cpp:113:90: required from here
/usr/include/c++/8/thread:240:2: error: no matching function for call to ‘std::thread::_Invoker<std::tuple<void (*)(short int*, int, int, int), short int*, int, int, int, in
 
CK.
3:17 PM
Are you sure that error's coming from the code you pasted? _Callable = void (&)(short int*, int, int, int) does not match filterfcts signature
 
 
4 hours later…
7:16 PM
Hi folks, how to define an array of 2 pointers to array of int?
 
7:28 PM
You could achieve it with this:
std::array<int*,2> arr0;
int* arr1 = new int[3];
int* arr2 = new int[3];
That's if your pointed arrays don't have the same size.
 
@AlexandreVaillancourt: I don't want to use array.
Just for learning purposes.
 
You mean you don't want to use std::array?
 
int* arr0[2];
arr0[0] = new int[3];
arr0[1] = new int[3];
Don't forget to delete them :)
 
8:21 PM
@GodMustBeCrazy why? it's the idiomatic way to do statically sized arrays in c++.
 
8:39 PM
@Mgetz: I already got the answer. Thanks!


void case6()
{
	int input[2][3][4] =
	{
		{
			{1,2,3,4},
			{5,6,7,8},
			{9,10,11,12}
		},
		{
			{13,14,15,16},
			{17,18,19,20},
			{21,22,23,24}
		}
	};

	//int(*output)[3][4] = input;

	int* aux1[][3] =
	{
		{input[0][0], input[0][1], input[0][2]},
		{input[1][0], input[1][1], input[1][2]}
	};

	int** aux2[] = { aux1[0],aux1[1] };

	int*** output = aux2;

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int k = 0; k < 4; k++)
I leave now.............
 
9:05 PM
How does scoped enum make sure the value stays consistent across compilation / platforms / I don't know what? If for instance, one were to store the scoped enum value in a file <insert hand waving about how that happens>, application gets changed, recompiled, and old status get read from the file?
 
@FélixGagnon-Grenier if you want that you have to specify a base type and values, as well as do serialization logic
scoping the enum doesn't do that
 
right. serialization, so that the Status::OK gets transformed into a file-storable format, like "1"?
not sure I get what you mean with base type and values. you mean assigning manually values to the different members of the enum?
like enum class Status { ok = 1, wrong = 2 };?
 

« first day (913 days earlier)      last day (1946 days later) »