Created
September 19, 2023 06:17
-
-
Save MShrimp4/1f984727d3eefb3a1324424364bb9c04 to your computer and use it in GitHub Desktop.
Templated Inline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdio.h> | |
template<size_t x, size_t y> | |
void doSomething2(double (&arr)[x][y]) | |
{ | |
for (int i = 0; i < x; i++) | |
for (int j = 0; j < y; j++) | |
arr[i][j] = i * x + j; | |
} | |
int main() | |
{ | |
double arr2[10][10][10]; | |
doSomething2(arr2[0]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stddef.h> | |
#include <stdio.h> | |
int x = 10; | |
int y = 10; | |
void doSomething(double** arr) //arr[10][10] | |
{ | |
for (int i = 0; i < x; i++) | |
for (int j = 0; j < y; j++) | |
arr[i][j] = i * x + j; | |
} | |
int main() | |
{ | |
double*** arr = new double**[10]; | |
for(int i = 0; i<10;i++) | |
{ | |
arr[i] = new double*[10]; | |
for(int j=0; j<10; j++) | |
arr[i][j] = new double[10]; | |
} | |
doSomething(arr[0]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment