[970929] Recursive copy constructor

Chip Salzenberg chip@rio.atlantic.net
Mon Oct 6 19:40:00 GMT 1997


Given this code, 970929 generates code for Derived::Derived(const Derived &)
that calls itself:

    class Base {
      public:
        Base() : xi(0) {}
      private:
        int xi;
    };

    class Derived : public Base {
      public:
        Derived(const Derived &d);
        void assign(Base b);
    };

    Derived::Derived(const Derived &d)
    {
        assign(d);
    }

I'd say that Derived::Derived should be calling Base::Base(Base &) (as
implicitly defined), but not itself (Derived::Derived(const Derived &)),
in order to create the parameter for assign().

 Reading specs from /usr/local/lib/gcc-lib/i486-pc-linux-gnu/egcs-2.90.11/specs
 gcc version egcs-2.90.11 970929 (gcc2-970802 experimental)

-- 
Chip Salzenberg          - a.k.a. -           <chip@pobox.com>
        "He's Mr. Big of 'Big And Tall' fame."  // MST3K



More information about the Gcc mailing list