Having problems with a const reference parameter in function

I am a beginning and am testing my skills with the C++ driver for the MongoDb database. I've written this function:

void printQuery(DBClientConnection &c, std::string &dc, const Query &qu = BSONObj(), std::string sortby = "" )

This fragment:

cursor = c.query(dc,qu.sort(sortby))

raises the error:

error C2663: 'mongo::Query::sort' : 2 overloads have no legal conversion for 'this' pointer.

I believe this is something to do with using const Query with its member function sort. But if I change it to Query& without the const, then my parameter initialization = BSONObj() raises:

cannot convert from 'mongo::BSONObj' to 'mongo::Query &'

If I pass Query qu by value, then neither of these problems arise.

Is there a way to avoid either error? Is it really bad form to use a default value for a param?
Last edited on
Topic archived. No new replies allowed.