2013-04-10 5 views
0

다른 클래스의 개인 정적 변수 (* PhysicsEngine :: _world -> setDebugDrawer (&; debugDraw); *)에 액세스하려고합니다.C++ 다른 클래스의 private static 변수에 액세스하는 방법

일등석 :

namespace GameEngine 
{ 
    class PhysicsEngine 
    { 
    private: 
     // Pointer to Bullet's World simulation 
     static btDynamicsWorld* _world; 

2 등석 :가 0xc0000005 : 나는 나는 Bullet01.exe에서 0x00EC6910에서 처리되지 않은 예외가 _world 공개 할 경우

bool Game::initialise() 
    { 
     _device = irr::createDevice(irr::video::EDT_OPENGL, 
            _dimensions, 
            16, 
            false, 
            false, 
            false, 
            &inputHandler); 

     if(!_device) 
     { 
      std::cerr << "Error creating device" << std::endl; 
      return false; 
     } 
     _device->setWindowCaption(_caption.c_str()); 

    ////////////// 
    DebugDraw debugDraw(game._device); 
    debugDraw.setDebugMode(
    btIDebugDraw::DBG_DrawWireframe | 
    btIDebugDraw::DBG_DrawAabb | 
    btIDebugDraw::DBG_DrawContactPoints | 
    //btIDebugDraw::DBG_DrawText | 
    //btIDebugDraw::DBG_DrawConstraintLimits | 
    btIDebugDraw::DBG_DrawConstraints //| 
    ); 
    PhysicsEngine::_world->setDebugDrawer(&debugDraw); 

위치를 0x00000000 읽기 액세스 위반.

+0

을 노출? –

+6

당신이 어떤'friend's를 필요로하는 것처럼 들린다 –

+0

@CaptainObvlious 또는 적절한 디자인 –

답변

1

개인 정적 변수 _ 월드에 대한 참조 또는 포인터를 반환하는 Physics Engine 클래스의 일부 정적 함수를 노출 한 다음 해당 정적 함수를 호출합니다. 당신이 다음을 공개하지 왜 외부에서 도달 싶다면

PhysicsEngine::getWorld()->setDebugDrawer(&debugDraw); 

는 아래의 방법

static btDynamicsWorld* getWorld() { return _world; } 
+0

근무 해 주셔서 감사합니다 ...하지만 난 여전히 액세스 위반이 발생합니다. 아마도 Bullet Physics에 대해 더 자세히 살펴 봐야 할 것입니다. –

+0

어떤 액세스 위반이 있습니까? 위의 방법을 공개적으로 사용 했습니까? – Rush

+0

나는 내 어리 석음을 깨닫고 사적인 공간에 배치했다. 나는 일했다고 생각했지만 액세스 위반은받지 않았다. 이제 오류 C2248이 발생합니다 : 'GameEngine :: PhysicsEngine :: getWorld': 'GameEngine :: PhysicsEngine'클래스에 선언 된 비공개 멤버에 액세스 할 수 없습니다. –

0

이 클래스에서이 클래스를 친구로 선언하십시오. 그런 다음 해당 클래스의 구성원 함수는이 개인 정적 멤버에 액세스 할 수 있습니다.