This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]