🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Glen Ditchfield Tue, 05 Dec 1989 20:22
Contravariance warning
#681
Author: Glen Ditchfield
Date: Tue, 05 Dec 1989 20:22
55 lines
2283 bytes
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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads