bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

templates and inheritance


From: Greg Bacon
Subject: templates and inheritance
Date: Fri, 12 Apr 2002 16:18:40 -0000

The following small example fails on both g++ and MSVC++ 6.0.  Is this a
compiler bug or a bug in my understanding of the semantics?

    [11:13] hslinux% cat example.cpp
    #include <iostream>

    using std::cout;

    class A {
      public:
        A() { cout << "A::A called\n"; }

        // yes, should return a reference
        virtual void operator = (int i) = 0;

        virtual void operator = (float f) = 0;
    };

    template <class T>
    class B: public A {
      public:
        B() { cout << "B::B called\n"; }

        virtual void operator = (int i) {
            cout << "B::op= (int " << i << ")\n";
        }

        virtual void operator = (float f) {
            cout << "B::op= (float " << f << ")\n";
        }
    };

    template <class T>
    class C: public B<T> {
      public:
        C() { cout << "C::C called\n"; }
    };

    int
    main()
    {
        B<float> b;
        C<float> c;

        b = 3.14159f;
        c = 2.71828f;

        // fully qualifying compiles without complaint, however
        // c.B<float>::operator=(2.71828f);

        return 0;
    }
    [11:13] hslinux% g++ -ansi -Wall -pedantic -o example example.cpp
    example.cpp: In function `int main()':
    example.cpp:42: no match for `C<float>& = float' operator
    example.cpp:30: candidates are: C<float>& C<float>::operator=(const 
C<float>&)
    [11:14] hslinux% g++ --version
    g++ (GCC) 3.2 20020411 (experimental)
    Copyright (C) 2002 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Thanks,
Greg
-- 
The most secure safety net in the world is the generosity of family, friends,
churches, service clubs, foundations, the United Way, and other charitable
agencies . . . Government bureaucrats are determined to enlarge their power
by keeping as many people as possible on welfare.     -- Harry Browne



reply via email to

[Prev in Thread] Current Thread [Next in Thread]