Pergunta

i am trying to change a code from regular functions to "Member function pointers" everything work fine but i have no idea how to define the pointer to operator

before the main i wrote

typedef int*(tArray_t<int>::*op)(int)const;

then inside the main

int main(){
//...
op oper=&tArray_t<int>::operator[];


    cout<<*intArray[2]<<endl;   // how do i change it here ?????????? 
//...

}
Foi útil?

Solução

Here is a toy example using operator ! and a member pointer to it, looks like VC++ 10 was ok with it:

class Test
{
public:
    bool operator !() {return true;};   
};

typedef bool (Test::* memfunptr)();

int main(){

Test tt;
memfunptr mf = &Test::operator!;

bool res = (tt.*mf)();

return 0;
}

So, try something along the lines of:

tArray_t intArray;
(intArray.*insert)(&((intArray.*op)(1)));  

(Not sure what your actual definitions of intArray and insert are, so I'm guessing here that intArray is an instance and insert is another member ptr)

Outras dicas

    tArray_t<int> intArray;

i have changed this

*intArray[2]

with this , now it works , thx :)

(*(intArray.*oper)(2)) 
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top