Hi,
I am using build 1548 of Visual Assist X. I noticed a problem when extracting some code that uses pointers to members: the method that is created misses some parameters... Consider the following code:
class Elem;
class K {
int getNumberOfElements() const;
Elem* getElement(int) const;
void method();
};
void K::method() {
int (K:: *getNb)() const;
getNb = &K::getNumberOfElements;
Elem* (K:: * get)(int) const;
get = &K::getElement;
for (int i = 0; i < (this->*getNb)(); ++i) {
Elem* elem = (this->*get)(i);
// Do something with elem
}
}
Select the whole 'for' loop (the blue lines), and choose 'Extract Method'. You get the following incorrect code:
class Elem;
class K {
int getNumberOfElements() const;
Elem* getElement(int) const;
void method();
void MyMethod() {
for (int i = 0; i < (this->*getNb)(); ++i) {
Elem* elem = (this->*get)(i);
// Do something with elem
}
}
};
void K::method() {
int (K:: *getNb)() const;
getNb = &K::getNumberOfElements;
Elem* (K:: * get)(int) const;
get = &K::getElement;
MyMethod();
}
instead of
class Elem;
class K {
int getNumberOfElements() const;
Elem* getElement(int) const;
void method();
void MyMethod(int (K:: *getNb)() const, Elem* (K:: * get)(int) const) {
for (int i = 0; i < (this->*getNb)(); ++i) {
Elem* elem = (this->*get)(i);
// Do something with elem
}
}
};
void K::method() {
int (K:: *getNb)() const;
getNb = &K::getNumberOfElements;
Elem* (K:: * get)(int) const;
get = &K::getElement;
MyMethod(getNb, get);
}
Not a big deal (I don't write such code every day...), but I thought you'd like to know...
Thanks.