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

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

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux