This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Problem with private copy constructor
- From: Mathias Froehlich <M dot Froehlich at science-computing dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 26 Jun 2006 11:57:41 +0200
- Subject: Problem with private copy constructor
Hi,
I have a problem with that following code together with gcc-4.1.1.
#include <iostream>
class base {
public:
base()
{ std::cout << __PRETTY_FUNCTION__ << " " << this << std::endl; }
private:
base(const base&);
};
class derived : public base {
public:
derived()
{ std::cout << __PRETTY_FUNCTION__ << " " << this << std::endl; }
};
void fuu(const base& b)
{
}
int main()
{
fuu(derived());
return 17;
}
gcc bails out with the following error message:
gcctest2.cpp: In copy constructor 'derived::derived(const derived&)':
gcctest2.cpp:8: error: 'base::base(const base&)' is private
gcctest2.cpp:11: error: within this context
gcctest2.cpp: In function 'int main()':
gcctest2.cpp:23: note: synthesized method 'derived::derived(const derived&)'
first required here
>From my understanding of c++, I would not expect that this copy constructor is
called in this case. In fact, gcc-3.3.4 and various other UNIX c++ compilers
do not need that copy constructor either.
Do I need to dig out my copy of the C++ standard or is it something to file a
bugreport?
Greetings
Mathias
--
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511