Is createDevice a function?

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
Pythy Python
Posts: 30
Joined: Sun Mar 29, 2015 1:31 am

Is createDevice a function?

Post by Pythy Python »

Code: Select all

IrrchitDevice *device = createDevice();
I thought class(IrrchitDevice) can't assign its value to a function(createDevice). Or is IrrchitDevice not a class?

(sorry i'm new to c++)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Is createDevice a function?

Post by CuteAlien »

It's 'IrrlichtDevice' and it is a class. What this line does is that it calls the function createDevice(). Which returns a pointer to a class-instance (also called object) of IrrlichtDevice. As the function name hints it has created that object internally. And the pointer to that object is assigned to the variable device which is also of type IrrlichtDevice* (pointer to an object of class IrrlichtDevice).
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
wangmopp
Posts: 3
Joined: Thu Apr 02, 2015 10:28 am

Re: Is createDevice a function?

Post by wangmopp »

"createDevice()"is a function call with default parameter,this function will generate a IrrlichtDevice object at heap and return it's pointer! I'm also new to irrlicht!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Is createDevice a function?

Post by Mel »

Yes. createDevice is a function. In fact, you could say this function precisely it is a bit closer to C than C++ with regard to its usage. It creates an instance of the class "IrrlichtDevice" with new, and returns its pointer, in a nutshell.

There is a way to not get confused with the functions and the methods. Basicly, if it is not inside a class, it is a function, if it belongs to a class, it is a method.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply