1

I am wondering how to express the parameters of the constructor when I put the 2-dimensional array in reference format. I don't know how to write *, &, etc...

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
강정민
  • 23
  • 2
  • Classes and Class constructors are not defined in C... – m0hithreddy Jun 20 '20 at 04:36
  • this is c++. my tag was wrong... – 강정민 Jun 20 '20 at 04:38
  • You can use `type function(type arr[][3]){ ... }` or `type function(type (*arr)[3]){ ... }`, both are the same. Pass it using: `type arr[2][3]; function(arr);` – David Ranieri Jun 20 '20 at 04:39
  • I want to take a two-dimensional array of main functions and store it in the private of the class, and if the array is changed in private, the value of the original array of the main function can also be changed. – 강정민 Jun 20 '20 at 04:44
  • 1
    If the array dimension are fixed (known) at compile time, you can use `function(type (&arr)[2][3])`. However, this ONLY works if all dimensions are fixed (unless the constructor is templated on the unknown dimensions, which has lots of trade-offs). Rather than using raw arrays, consider using standard containers - such as `std::vector >` or (if array dimensions are fixed) `std::array, first_dimension>`. Standard containers can be passed by value or reference like any other object. – Peter Jun 20 '20 at 05:14

0 Answers0