boost::priority_queue help

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

boost::priority_queue help

Boost - Users mailing list

Created a boost::priority_queue with my comparison operation defined. Here is how my priority_queue looks,

boost::heap::priority_queue<myObject*, boost::heap::compare<myObjectPtrCompare> > max_heap;

My comparison is defined as,

struct myObjectPtrCompare
{
    bool operator()(const myObject* lhs, const myObject* rhs) const
    {
        return (lhs->getTime() < rhs->getTime());
    }
};

I have used it as,

myObject* obj1 = static_cast<myObject*>(base1);

'base1' is an object of class 'myBase'(base class of myObject)

myObject and getTime() within it used for comparision are defined as,

class myObject : public myBase {
    Time getTime() const { return time; }
.
.
. 
...
}

Compiling this gives me this error,

c:\Projects\pq_test.cpp(27): error C2662: 'void boost::heap::priority_queue<myObject*,boost::heap::compare<myObjectPtrCompare>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>::push(myObject *const &)' : cannot convert 'this' pointer from 'const boost::heap::priority_queue<myObject *,boost::heap::compare<myObjectPtrCompare>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>' to 'boost::heap::priority_queue<myObject *,boost::heap::compare<myObjectPtrCompare>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_> &'
1>          Conversion loses qualifiers

Using Visual Studio 2013 C++. I understand that I am doing something wrong with const correctness, but I am not able to figure out what is wrong. Any help is appreciated.

TIA!


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::priority_queue help

Boost - Users mailing list
AMDG

On 12/08/2017 04:38 AM, Ram via Boost-users wrote:

> <snip>
>
> c:\Projects\pq_test.cpp(27): error C2662: 'void
> boost::heap::priority_queue<myObject*,boost::heap::compare<myObjectPtrCompare>>::push(myObject
> *const &)' : cannot convert 'this' pointer from 'const
> boost::heap::priority_queue<myObject
> *,boost::heap::compare<myObjectPtrCompare>>'
> to 'boost::heap::priority_queue<myObject
> *,boost::heap::compare<myObjectPtrCompare>>
> &'1>          Conversion loses qualifiers
>
> Using Visual Studio 2013 C++. I understand that I am doing something wrong
> with const correctness, but I am not able to figure out what is wrong. Any
> help is appreciated.
>

You're trying to push onto a const priority_queue.

In Christ,
Steven Watanabe



_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::priority_queue help

Boost - Users mailing list
Yes thanks Steven! The queue was modified inside a const method of the class. I corrected it but now I get these warning(we treat them as errors). These are the warnings,

1>  priority_queue_example.cpp
1>c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(102): error C2220: warning treated as error - no 'object' file generated
1>c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(102): warning C4100: 'rhs' : unreferenced formal parameter
1>          c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(102) : while compiling class template member function 'boost::heap::detail::size_holder<false,size_t>::size_holder(const boost::heap::detail::size_holder<false,size_t> &)'
1>          c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(189) : see reference to function template instantiation 'boost::heap::detail::size_holder<false,size_t>::size_holder(const boost::heap::detail::size_holder<false,size_t> &)' being compiled
1>          c:\Projects\lib\boost\boost\heap\detail\stable_heap.hpp(151) : see reference to class template instantiation 'boost::heap::detail::size_holder<false,size_t>' being compiled
1>          c:\Projects\lib\boost\boost\heap\priority_queue.hpp(65) : see reference to class template instantiation 'boost::heap::detail::heap_base<T,myObjectPtrCompare,false,unsigned __int64,false>' being compiled
1>          with
1>          [
1>              T=myObject *
1>          ]
1>          c:\Projects\priority_queue_example.h(193) : see reference to class template instantiation 'boost::heap::priority_queue<myObject *,boost::heap::compare<myObjectPtrCompare>,boost::parameter::void_,boost::parameter::void_,boost::parameter::void_>' being compiledcompare<ObjectPtrCompare>,boost::parameter::void_,boost::parameter::void

My priority_queue is declared as,

mutable boost::heap::priority_queue<myObject*, boost::heap::compare<myObjectPtrCompare> > hp;

Can you please help me fix this, I have been trying to for 2 days. Not sure what this means.

This is my comparison class defined,

struct myObjectPtrCompare
{
bool operator()(const myObject* lhs, const myObject* rhs) const
{
return (lhs->getProp() < rhs->getProp());
}
};
 
Can you please help with this? I understand that 'rhs' is unused, but in my implementation, it is used but the warning is pointing to boost code. I don't understand it.

Thanks!

On Sat, Dec 9, 2017 at 9:56 AM, Steven Watanabe via Boost-users <[hidden email]> wrote:
AMDG

On 12/08/2017 04:38 AM, Ram via Boost-users wrote:
> <snip>
>
> c:\Projects\pq_test.cpp(27): error C2662: 'void
> boost::heap::priority_queue<myObject*,boost::heap::compare<myObjectPtrCompare>>::push(myObject
> *const &)' : cannot convert 'this' pointer from 'const
> boost::heap::priority_queue<myObject
> *,boost::heap::compare<myObjectPtrCompare>>'
> to 'boost::heap::priority_queue<myObject
> *,boost::heap::compare<myObjectPtrCompare>>
> &'1>          Conversion loses qualifiers
>
> Using Visual Studio 2013 C++. I understand that I am doing something wrong
> with const correctness, but I am not able to figure out what is wrong. Any
> help is appreciated.
>

You're trying to push onto a const priority_queue.

In Christ,
Steven Watanabe



_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users