-2
++ C에서 구조체의 2 차원 배열을 전달. 지금까지 한 차원에서 작동하는 코드는 있지만 두 차원으로 확장하는 데 문제가 있습니다. 여기까지 내가 무엇을 가지고 있습니다 :내가 벡터를 사용하지 않고 구조체의 2 차원 배열을 셔플하려고
#include <iostream>
#include <algorithm>
#include <time.h>
using namespace std;
struct bingo {
int set1;
int set2;
};
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
void randomize(int arr[], int n) {
srand(time(NULL));
for(int i = n-1; i > 0; i--) {
int j = rand() % (i + 1);
swap(&arr[i], &arr[j]);
}
}
int main() {
const int n = 28;
bingo arr[n] = { // array of structs
{0,1}, {1,2}, {2,3}, {3,4}
};
randomize(arr, n); // My error happens here and it says "cannot convert
// "bingo* to int* for argument '1' to void randomize(int*, int)
for(int i = 0; i < n; i++) {
std::cout << arr[i].set1 << arr[i].set2 << endl;
}
return(0);
}
음, 그래. 'randomize()'는'int *'를 취하고 '빙고'는 취하지 않습니다. 먼저 '빙고'를 사용하기 위해 그 기능을 변경해야합니다. – mauzel
이 C 또는 C++입니까? 당신은 C라고하지만 C++라고 태그를 붙인다. 문 및 표준'의 사용을 포함에서 C. – Vality
@Vality의 언급 : 그것은 분명 C++의 cout'이 유효 C하거나 제거하십시오 중 하나. OP는 사용 된 실제 언어에 대한 오해가있는 것 같습니다. 표준 : shuffle'가 있어야한다'대신'표준 : vector'와'표준 : random_shuffle' –