2013-05-21 3 views
3

포인터 관련 문제가 있습니다.포인터가 함수 헤더로 전달됩니다.

나는 다음 헤더와 기능이 있습니다

addActor (NxuPhysicsCollection &c, NxActor &a, const char *userProperties=0, const char *actorId=0) 

을 그리고는 다음과 같이 사용하는 것을 시도하고있다 :

NXU::NxuPhysicsCollection* collection = new NXU::NxuPhysicsCollection(); 
NxActor* actor = *actors++; 
NXU::addActor(collection, actor, NULL, NULL); 

그러나 나는 다음과 같은 오류 얻을 :

A reference of type "NXU::NxuPhysicsCollection&" (not const-qualified) cannot be initialised with a value of type "NXU::NxuPhysicsCollection*" (this is for the collection parameter, same error appears for actor as well)

제대로 작동하려면 컬렉션 및 액터 매개 변수를 함수에 전달해야합니다.

나는이 시도 :

NXU::addActor(&collection, &actor, NULL, NULL); 

을하지만 그 중 하나 doesn''t는 일, 그것은 나에게 오류가 있습니다 : 어떤 도움을 주시면 더 좋구요

"Initial value of reference to non-const must be a lvalue." 

합니다.

편집 :이처럼 사용하는 경우 :

NXU::addActor((NXU::NxuPhysicsCollection&)collection, (NxActor&)actor, NULL, NULL); 

그것은 더 이상 나에게 오류를 제공하지 않습니다. 이 올바른지?

내가 NXU과 NX 네임 스페이스가 폐쇄 소스 것을 언급해야하고 나는 그들이 구현하는 방법을 수정할 수 없습니다

+0

'NXU :: addActor (& collection, & actor, NULL, NULL);'이 경우'collection'과'actor'를 어떻게 정의 했습니까? – Shark

+0

나는 그것을 시도했지만 효과가 없었다. – user2399378

답변

3

참조, 당신은 참조와 호환되도록 역 참조 포인터 필요 : 또는

// No need to pass NULLs for the defaulted parameters, so 
// the trailing NULL, NULL are removed. 
NXU::addActor(*collection, *actor); 

참조 대신 포인터를 받아들이도록 생성자의 시그니처를 변경할 수 있습니다.

addActor (NxuPhysicsCollection *c, NxActor *a, const char *userProperties=0, const char *actorId=0) 
//       ^  ^
//        |   | 
//        Here and Here 
+0

고맙습니다. 당신과 무 Juice가 나에게 정확한 답을주었습니다. 코드에 액세스 할 수 없기 때문에 코드에 대해 수정할 수 없습니다. – user2399378

0
NXU::addActor(*collection, *actor, NULL, NULL); 

addActor (NxuPhysicsCollection &c, NxActor &a, const char *userProperties=0, const char *actorId=0) 

가,하지에 의해 참조에 의해 collectionactor를 수신

때문에 포인터

3

ca 파라미터는 참조입니다.

는로 패스 :

NXU::addActor(*collection, *actor, NULL, NULL); 

이 행위는 포인터 역 참조라고합니다. collectionactor포인터가있는 동안 ca에 대한 멤버 함수의 형식 인수 이후

관련 문제