Bug? access to copy-constructor for operator= needed in gcc-4.0

Martin Kittel debian@martin-kittel.de
Sun Jun 12 10:15:00 GMT 2005


Hi,

I have the following code sample:


class A {
public:
    A() {}

    const A& operator=(const A& a) {
    }

private:
    A(const A& a) {};

};


class B {
    A m_a;

public:
    B() {
        // works fine
        A a;
        m_a = a;

        // needs access to copy-constructor, why?
        m_a = A();
    }
};

        
When trying to compile with gcc-4.0 I get the following error:

/tmp/copy-const.cpp: In constructor 'B::B()':
/tmp/copy-const.cpp:9: error: 'A::A(const A&)' is private
/tmp/copy-const.cpp:24: error: within this context

I can't see why it should be necessary to access the copy-constructor in the
line 'm_a = A();'. In my opinion a temporary should be created and then the
assignment operator be called, no need for the copy-constructor.

Is this a bug, or am I simply mistaken?

The gcc-version used is from Debian:

gcc-4.0 (GCC) 4.0.1 20050522 (prerelease) (Debian 4.0.0-9)


Thanks for any help.

Martin.



More information about the Gcc-help mailing list