# Static Functions

• 04-19-2011
JohnLeeroy
Static Functions
Hello,

I plan on making a D3DXVECTOR3 wrapper for my project and I was wondering if it was optimal to make math functions be static? Or wrap up the functionality in a class.

Quote:

#ifndef _Math_h_
#define _Math_h_

static float DotProduct(const D3DXVECTOR3 a, const D3DXVECTOR3 b)
I would invoke the function by :
Code:

```CVector3 vecA, vecB; float fDotResult = Math::DotProduct(vecA, vecB)```
OR

Code:

```#ifndef _Math_h_ #define _Math_h_ class CVector3 { public:       D3DXVECTOR3 mVector3;       float DotProduct(const D3DXVECTOR3 vec2);   };```
I can call this by ...

Code:

```CVector3 cVectorA, cVectorB; float fDotResult = cVectorA.DotProduct(cVectorB);```
From what I hear, static variables/functions are as slow as global variables/functions so I am curious as to which of the two cases above is better in terms of speed.
• 04-20-2011
Elysia
Quote:

Originally Posted by JohnLeeroy
From what I hear, static variables/functions are as slow as global variables/functions so I am curious as to which of the two cases above is better in terms of speed.

What? That is nothing but a false claim, if there is such a rumor.

As I see it, you can do two things, which depends on what you like and what you need.
Make a struct Vector3, and a namespace Math with vector operations.
Create a class Vector3 and add math functions to it.
Unless there is really any need for a class (ie some type of functionality that requires extra members as opposed to x, y, z), then I would suggest the first way, since it would allow for more flexibility (ie call them with derived classes, etc).