Skip to main content
gamedev.net
🔒 Locked

Function designs

Started by johnnyBravo 1 reply 550+ views
Original Post
johnnyBravo
johnnyBravo
Hi, i''m making alot of classes containing basic directx features, eg meshes, textures, vertices and so on. inside the classes i have functions eg set(D3DXVECTOR3 position, D3DXVECTOR2 textureCoords) say i don''t need to use the textureCoords would it be a good design idea to use pointers on the textureCoords etc so the user can enter NULL, if they don''t need to use it? eg set(D3DXVECTOR3 * position, D3DXVECTOR2 * textureCoords) //and using set(&D3DXVECTOR3(20,10,100),NULL); like the line above, is that a good idea, im just not sure because i am generally not sure about using pointers unless i do need them. Thankyou,
Qw3r7yU10p!
Qw3r7yU10p!
Using NULL would normally mean that whoever is using the function will have to look up whether it is okay to pass NULL.

Better would be to overload the function to have both:

set(D3DXVECTOR3 * position)

and

set(D3DXVECTOR3 * position, D3DXVECTOR2 * textureCoords)

where you have to pass a non-NULL to the second version

Best (to my mind) would be to pass references instead of pointers. Then you really couldn''t pass NULL even if you wanted to.

Then you can introduce a NullD3DXVECTOR which is derived from D3DXVECTOR but always has zero values.

That''s just me though.
johnnyBravo
johnnyBravo
quote:
Better would be to overload the function to have both:



the reason i dont want to do that, say for another example ive got this function:
setWorldMatrix(D3DXVECTOR3 position, D3DXVECTOR3 roation, D3DXVECTOR3 rotationPoint,D3DXVECTOR3 scale)

it would get a little bit messy after that to make overloaded functions,

And if i put such things standard, eg for positions etc only, not devices eg d3dDevice, dinputDevice,
so then you could assume when NULL is acceptable.


...........but if i did use pointers like so:
void function(float * rotation)
{
lp_Device->someDXfunction(&rotation);
}

would that be ok, like memory wise, or not crashing wise...
(i think thats how pointers go(in example), excuse me if im wrong, im always getting that stuff confused)

thanks,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.