gjditchfield@watmsg.waterloo.edu (Glen Ditchfield) (12/06/89)
Class Base defines a protected member function f with a function pointer
parameter. Class Derv defines a public member function f with a different
kind of function pointer parameter. I get a "contravariance violation"
warning. I don't think I should; I'm just overloading a name. By
comparision, doing the same thing with member function g and non-function
pointer arguments doesn't give a warning.
-------------------- contra.cc --------------------
#include <stream.h>
class Base {};
class Derv: public Base {};
typedef int (*BCF)(Base*, Base*);
typedef int (*DCF)(Derv*, Derv*);
class BaseCont {
protected:
void f(BCF) { cout << "BaseCont::f()\n"; };
void g(int*) { cout << "BaseCont::g()\n"; };
};
class DervCont: public BaseCont {
public:
void f(DCF) { cout << "DervCont::f()\n"; };
void g(char*) { cout << "DervCont::g()\n"; };
};
int dcf(Derv*, Derv*) { return 0; };
int main() {
char c;
DervCont dc;
dc.f(dcf); // line 26
dc.g(&c);
};
---------------------------------------------------
gcc -v -c contra.cc
gcc version 1.36.9
/usr/local/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -Dvax -Dunix -D__vax__ -D__unix__ contra.cc /usr/tmp/cc010778.cpp
GNU CPP version 1.36.9
/usr/local/lib/gcc-cc1plus /usr/tmp/cc010778.cpp -quiet -dumpbase contra.cc -version -o /usr/tmp/cc010778.s
GNU C++ version 1.36.1 (based on GCC 1.36) (vax) compiled by GNU C version 1.36.
default target switches: -munix
contra.cc: In function int main ():
contra.cc:26: warning: contravariance violation for method types ignored
/usr/local/lib/gcc-as -o contra.o /usr/tmp/cc010778.s
Compilation finished at Tue Dec 5 15:16:20
... on a VAX running BSD 4.3
Glen Ditchfield gjditchfield@violet.uwaterloo.ca Office: DC 2517
Dept. of Computer Science, U of Waterloo, Waterloo, Ontario, Canada, N2L 3G1
Gorbachev is a CIA mole.