This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: "No matching function" -- not finding copy constructor
On Tue, May 17, 2005 at 09:12:38AM -0700, Joe Buck wrote:
> On Tue, May 17, 2005 at 12:00:59PM -0400, Paul Koning wrote:
> > I'm upgrading to V4.0.0 and struggling with some code that's seriously
> > into templates. One puzzling error is this one:
> >
> > keyed_obj.hh:159: error: no matching function for call to 'CxnIndex::CxnIndex(CxnIndex)'
> > Indeces.hh:150: note: candidates are: CxnIndex::CxnIndex(CxnIndex&)
> > Indeces.hh:145: note: ... and some more
> >
> > It's not entirely clear to me why something very much like a copy
> > constructor is being invoked in the first place. But the bigger
> > puzzle is: why isn't the copy constructor being matched? I would have
> > thought that any call with a T argument should match a function or
> > method with an &T argument in its declaration...
>
> CxnIndex::CxnIndex(CxnIndex&) is not a general copy constructor. Notice
> the non-const reference. The error message is saying that it's trying
> to pass a temporary to a copy constructor. You would need
>
> CxnIndex::CxnIndex(const CxnIndex&)
>
> to match that. As for why you need a copy constructor, we'd have to
> see the code for that, but this list isn't really the right place for
> helping you debug this problem further.
One GCC-related point is possibly worth mentioning: GCC is now much
stricter about enforcing the rule that a copy constructor must be
accessible even if the copy will be elided.
See the last entry of http://gcc.gnu.org/bugs.html#nonbugs_cxx
jon