rifter1818
Junior Contributor
Well im lost doinging things well outside my current c++/c knowledge but that hasnt stopped me before.
What i want to do is at startup change the code paths of a few different functions, im pretty sure (at least some of them) can be done using function pointers (the how part is what im sketchy on). I know that the DirectXExtensions uses something like this so it can support SSE,3DNow etc.. which is what im trying to do funny enough.
first type of functions would be member functions...
Vector::Add(Vector V1,VectorV2);
....
and i would want to have multiple implementations of this function depending on what cpu is there....
my first thought on it (with my limited knowledge of function pointers) was something like this.
and have the class FUNCTIONPOINTERALLOCATER choose the right function for *ADDDEFAULT....
Second thought came to me instantly thats pretty stupid....
again having *ADD pointed to the right function.....
which might work im not sure how efficiant it would be but i cant see it being too bad... (ive been wrong before)
leaving question 2. is there a better way to do this?
and question
3) operators
if i can do it for member functions i can do it to operators right? please say yes.... and how.
Thanks in advance, ive searched the net for almost two days looking at everything i can read on function pointers but all that lead me to was something simular to the first method.
ps
And please dont say why bother D3DX allready has a good vector class. If you want an explination, "You dont have to reinvent the wheel but you should know how the wheel works before you use it" is about my philosiphy on the subject. and there are other uses (besides my quest for knowledge) for such things...
What i want to do is at startup change the code paths of a few different functions, im pretty sure (at least some of them) can be done using function pointers (the how part is what im sketchy on). I know that the DirectXExtensions uses something like this so it can support SSE,3DNow etc.. which is what im trying to do funny enough.
first type of functions would be member functions...
Vector::Add(Vector V1,VectorV2);
....
and i would want to have multiple implementations of this function depending on what cpu is there....
my first thought on it (with my limited knowledge of function pointers) was something like this.
Code:
class Vector
{
friend class FUNCTIONPOINTERALLOCATER; // its init calls change all the function pointers to the correct ones...
protected:
Vector (*ADDDEFAULT)(Vector v1,Vector v2);
public:
Vector Add(Vector v1,Vector v2,Vector (*ADDFUNC)(Vector V1,Vector V2) = ADDDEFAULT);
}
Second thought came to me instantly thats pretty stupid....
Code:
class Vector
{
friend class FUNCTIONPOINTER....;//
public:
Vector (*ADD)(Vector v1,Vector v2);
}
which might work im not sure how efficiant it would be but i cant see it being too bad... (ive been wrong before)
leaving question 2. is there a better way to do this?
and question
3) operators
if i can do it for member functions i can do it to operators right? please say yes.... and how.
Thanks in advance, ive searched the net for almost two days looking at everything i can read on function pointers but all that lead me to was something simular to the first method.
ps
And please dont say why bother D3DX allready has a good vector class. If you want an explination, "You dont have to reinvent the wheel but you should know how the wheel works before you use it" is about my philosiphy on the subject. and there are other uses (besides my quest for knowledge) for such things...