我想從另一個類訪問一個私有靜態變量(* PhysicsEngine :: _world - > setDebugDrawer(& debugDraw); *)。C++如何訪問另一個類中的私有靜態變量
第一類:
namespace GameEngine
{
class PhysicsEngine
{
private:
// Pointer to Bullet's World simulation
static btDynamicsWorld* _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);
如果我讓_world公共我得到未處理的異常在0x00EC6910在Bullet01.exe:0000005:訪問衝突讀取位置00000000。
如果你想從外面爲什麼不把它公開,然後實現它? – 2013-04-10 13:56:22
聽起來像你需要一些'朋友' – 2013-04-10 13:56:29
@CaptainObviously或適當的設計 – 2013-04-10 14:02:06