M
Maciej Kwapulinski
hallo,
the following program works OK:
#include <stdio.h>
struct A {
bool fun(int a, int b) {
return a == b;
}
bool (A::*ptr)(int a, int b);
A() {
ptr = &A::fun;
}
bool fun_ptr(int a, int b) {
return (A:tr)(a, b);
}
};
main() {
A a;
printf ("%d\n", a.fun_ptr(4,4) );
printf ("%d\n", a.fun_ptr(4,3) );
}
But, after changing into STL class:
#include <stdio.h>
template <class T>
struct A {
bool fun(T a, T b) {
return a == b;
}
bool (A::*ptr)(T a, T b);
A() {
ptr = &A::fun;
}
bool fun_ptr(T a, T b) {
return (A:tr)(a, b); // this is line 15
}
};
main() {
A<int> a;
printf ("%d\n", a.fun_ptr(4,4) );
printf ("%d\n", a.fun_ptr(4,4) );
}
during compilation the following error occures:
/home/mkwap/BGP-cvs/ccc/p11.cpp: In method `bool
A<int>::fun_ptr<int>(int, int)':
/home/mkwap/BGP-cvs/ccc/p11.cpp:21: instantiated from here
/home/mkwap/BGP-cvs/ccc/p11.cpp:15: pointer-to-member function
A<int>:tr cannot be called
/home/mkwap/BGP-cvs/ccc/p11.cpp:15: without an object; consider
using .* or ->*
Do You know what is the problem and what to do to make second
program run
Greetings
Maciej
the following program works OK:
#include <stdio.h>
struct A {
bool fun(int a, int b) {
return a == b;
}
bool (A::*ptr)(int a, int b);
A() {
ptr = &A::fun;
}
bool fun_ptr(int a, int b) {
return (A:tr)(a, b);
}
};
main() {
A a;
printf ("%d\n", a.fun_ptr(4,4) );
printf ("%d\n", a.fun_ptr(4,3) );
}
But, after changing into STL class:
#include <stdio.h>
template <class T>
struct A {
bool fun(T a, T b) {
return a == b;
}
bool (A::*ptr)(T a, T b);
A() {
ptr = &A::fun;
}
bool fun_ptr(T a, T b) {
return (A:tr)(a, b); // this is line 15
}
};
main() {
A<int> a;
printf ("%d\n", a.fun_ptr(4,4) );
printf ("%d\n", a.fun_ptr(4,4) );
}
during compilation the following error occures:
/home/mkwap/BGP-cvs/ccc/p11.cpp: In method `bool
A<int>::fun_ptr<int>(int, int)':
/home/mkwap/BGP-cvs/ccc/p11.cpp:21: instantiated from here
/home/mkwap/BGP-cvs/ccc/p11.cpp:15: pointer-to-member function
A<int>:tr cannot be called
/home/mkwap/BGP-cvs/ccc/p11.cpp:15: without an object; consider
using .* or ->*
Do You know what is the problem and what to do to make second
program run
Greetings
Maciej