joe@proto.COM (Joe Huffman) (08/07/90)
The following compiles and runs just fine under Zortech C++ but Turbo C++ complains about mismatched parameters in the function main(). Which is correct? Note that this is just a quick and dirty test case not 'real' code, bounds checking, etc would normally be done. I can think up reasons why this would not be allowed, but also it is very useful to allow this (I have lots of code that does this type of thing, makeing Turbo C++ a major undertaking to port to). Where in E & S, ARM is this covered (if it is)? If this is obvious stuff to other people, just send email. No need to clutter up the newsgroup if I am attempting to do something illegal that Zortech lets me get away with. ----- test.cpp ----- #include <stdio.h> #include <string.h> class base { private: int array[10]; public: int traverse(int (*func_p)(base &this_object, int this_element)); int &get(int i) { if(i > 0 && i < 10) return array[i]; else return array[0]; } }; int base::traverse(int (*func_p)(base &this_object, int this_element)) { int flag = 1; for(int i = 0; i < 10 && flag; i++) flag = (*func_p)(*this, array[i]); return flag; } class derived: public base { private: char name[10]; public: char *set(const char *n) {return strncpy(name,n,10);} char *get_name(void) {return name;} }; static int traverse_func(derived &this_object, int this_element) { printf ("name = %s, element = %d\n", this_object.get_name(), this_element); return 1; // Continue traversal. } int main() { derived obj; obj.set("obj: "); for (int i = 10; i >= -1; i--) obj.get(i) = i; obj.traverse(traverse_func); // ^^ Turbo complains here ^^ return 0; } --- Zortech is my major source of income. Statements about them or their competitors cannot be totally without bias. -- joe@proto.com uunet!proto!joe FAX: 208-263-8772