Why is intermediate var used to set the struct member?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
carlwryker
Posts: 22
Joined: Sun Jun 12, 2016 8:03 am

Why is intermediate var used to set the struct member?

Post by carlwryker »

In the user interface example, why is an intermediate variable used to set the struct member device?

Code: Select all

 
struct SAppContext
{
    IrrlichtDevice *device;
   /* stuff  */
};
 
 
/* stuff */
 
IrrlichtDevice * device = createDevice(driverType, core::dimension2d<u32>(640, 480));
 
/* stuff */
 
SAppContext context;
context.device = device;
 
Is there a reason why the struct member isn't used directly like this, so, whenever we need to access the device, we just use context.device instead of device?

Code: Select all

 
SAppContext context;
 
/* stuff */
 
context.device = createDevice(driverType, core::dimension2d<u32>(640, 480));
 
Code::Blocks
mingw
Windows 10 64-bit
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Why is intermediate var used to set the struct member?

Post by CuteAlien »

I guess no real reason. Could as well create the SAppContext earlier and directly set context.device in it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
carlwryker
Posts: 22
Joined: Sun Jun 12, 2016 8:03 am

Re: Why is intermediate var used to set the struct member?

Post by carlwryker »

Thank you!
Code::Blocks
mingw
Windows 10 64-bit
Post Reply