두 개의 다른 구조체를 함수에 전달하는 방법을 알아야합니다. 멤버다른 구조체를 함수에 전달 (void * 사용)
warning: dereferencing 'void *' pointer
error: request for member left in something not a structure or union
같은 오류가 바로 여기
내가 (코드는 컴파일되지 않을 수 있음) 일반적인 용어로 무슨 짓을 : 나는 매개 변수에 대한 무효 *를 사용하지만 난이 오류가 발생하고 시도했다.
struct A{
char *a;
struct A *left, *right;
} *rootA;
struct B{
char *b;
struct B *left, *right;
} *rootB;
void BinaryTree(void *root, void *s){
if(condition)
root->left=s;
else if(condition)
BinaryTree(root->left, s);
if(condition)
root->right=s;
else if(condition)
BinaryTree(root->right, s);
}
int main(){
// Assume the struct of nodeA and nodeB get malloc()
// as well as the variables a and b with actual data.
struct A nodeA;
struct B nodeB;
BinaryTree(rootA, nodeA);
BinaryTree(rootB, nodeB);
return 0
}
코드는 포인터를 전달하고 있지 않음을 나타냅니다. 'BinaryTree (rootA, & nodeA)'등을 의미 했습니까? – lurker
nodeA와 nodeB의 메모리 위치를 전달 중입니다. 함수의 매개 변수에있는 void 포인터는 함수 no에서 사용할 수 있도록 역 참조해야합니다. – user2644819
매개 변수 유형은 포인터입니다. 구조체에 대한 포인터가 아니라 전체 구조체를 전달하고 있습니다. 물론 그 이상의 문제가있을 수 있습니다. 컴파일러는 구조체를 void 포인터로 "역 참조"하지 않습니다. – lurker