我想从另一个类访问一个私有静态变量(* 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