Re: Odd error I can't seem to recreate
On Fri, 04 Nov 2011 19:52:56 +0100, Noah Roberts <roberts.noah@gmail.com=
=
wrote:
In a significant code base I'm running into this problem:
This works:
test_service service;
std::string result = job->run_query(service);
This does not.:
std::string result = job->run_query(test_service());
the run_query function expects a const reference to test_service's
base class:
struct location_job
{
virtual ~location_job() {}
virtual std::string run_query(location_service const& service) const
= 0;
};
The error I get from g++4.1.2 is:
pipe_processor_test.cpp:142: error: no matching function for call to
=E2test_service::test_service(test_service)=E2
../inc/test_service.h:27: note: candidates are:
test_service::test_service(bool)
../inc/test_service.h:7: note:
test_service::test_service(test_service&)
The bool constructor is made by me, but the non-const copy constructor=
is the compiler's. Line 7 is the opening brace for the class.
I can't make any sense of this. Does anyone have ANY idea what might
be going on so I can try to narrow it down and create a minimal
example to get better help? The attempts I've made so far work
fine.
Under what conditions in which the first could work might the second
not when the parameter is const ref? I can't think of any.
Thanks for any help that can be provided. I know it's a reach.
Try looking at the copy constructors of test_service's members:
- the direct and virtual base classes
- the non-static data members
At least one of them should have a copy constructor without
const-qualification on the first parameter, which is why the
compiler-generated copy constructor of test_service lacks it as
well.
-- =
Gennaro Prota | name.surname gmail.com
Breeze C++ (preview): <http://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.