Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
发送包含2个整数的数组作为参数 我试图使C++代码更抽象,更容易理解和理解,占用更少的空间。它是一个以字符串和两个整数表示大小和位置的函数 HWND CreateButon(string Title, const int[2] Size, const int[2] Position) { // Create the control, assign title, size and position // Return HWND } HWND MyButton = CreateButton("Button1", [100, 20], [10, 10]);_C++_Arrays_Integer_Arguments - Fatal编程技术网

发送包含2个整数的数组作为参数 我试图使C++代码更抽象,更容易理解和理解,占用更少的空间。它是一个以字符串和两个整数表示大小和位置的函数 HWND CreateButon(string Title, const int[2] Size, const int[2] Position) { // Create the control, assign title, size and position // Return HWND } HWND MyButton = CreateButton("Button1", [100, 20], [10, 10]);

发送包含2个整数的数组作为参数 我试图使C++代码更抽象,更容易理解和理解,占用更少的空间。它是一个以字符串和两个整数表示大小和位置的函数 HWND CreateButon(string Title, const int[2] Size, const int[2] Position) { // Create the control, assign title, size and position // Return HWND } HWND MyButton = CreateButton("Button1", [100, 20], [10, 10]);,c++,arrays,integer,arguments,C++,Arrays,Integer,Arguments,我知道最后一个是错的。我就是这样写的,这样你就能明白我的意思了。我想直接将大小和位置值作为参数发送。我可以使用structs,但它们必须在之前声明。其他变量也一样。我只想把它们作为两个整数的一组发送到参数中,我想知道是否有解决方法。最重要的是,它只是为了紧凑和简单。您可以传递一对而不是数组: HWND CreateButton(string Title, std::pair<int,int> Size, std::pair<int,int> Position); Cre

我知道最后一个是错的。我就是这样写的,这样你就能明白我的意思了。我想直接将大小和位置值作为参数发送。我可以使用
structs
,但它们必须在之前声明。其他变量也一样。我只想把它们作为两个整数的一组发送到参数中,我想知道是否有解决方法。最重要的是,它只是为了紧凑和简单。

您可以传递一对而不是数组:

HWND CreateButton(string Title, std::pair<int,int> Size, std::pair<int,int> Position);

CreateButton("Button1", {100, 20}, {10,10});                            // C++11
CreateButton("Button1", std::make_pair(100,20), std::make_pair(10,10)); // C++03

如果选择C++11,元组和统一大括号初始化是一种解决方案。这比我的解决方案要好。谢谢。这是一个很好的答案,因为结构是在别处定义的,所以保持了紧凑性。如果可以使用C++11,这是一个完美的解决方案。
CreateButton("Button1", Size(100,20), Position(10,10));