المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Members Named using Template Parameters



C++ Programming
04-07-2009, 08:01 PM
Is there a way to create a class that can be instantiated with different method names? For example, I would like to have an unnamed method in class foo, that can be renamed at compile time using template parameters (or some other method). I envision the class definition as follows:
template
class foo {
public:
double (MethodName)() {
return 0;
}
};And it would be instantiated/used in the following way
foo fooWithMethodASDF;
foo fooWithMethodMNBV;
double a = fooWithMethodASDF.asdf();
double m = fooWithMethodMNBV.mnbv();
The purpose behind attempting to do this is because I have two classes, both with three members of type double that have different names, and all other code is identical. Perhaps I could use properties with get/set methods in two different classes that inherit the public interface from the base class, but I am wondering if there is another way to implement this functionality? Thanks,

Sounds like somebody's got a case of the Mondays

-Jeff