Boost logo

Boost Users :

From: John Emmas (john_at_[hidden])
Date: 2021-09-07 15:43:36


Many thanks lon,

Just before your reply I spotted a conflict between my original use of
'animals' and the new usage. Sorry for the noise!

John

On 07/09/2021 16:33, Ion Gaztañaga via Boost-users wrote:
>>
>> But when I try that here, VS2019 throws up this compiler error:-
>>
>> error C2039: 'default_list_hook': is not a member of 'animal'
>>
>> Can anyone explain what I'm doing wrong??
>>
>> John
>
> It's difficult to see what's wrong without a full compilable example
> but the following snippet works perfectly for me in Visual 2019:
>
>
> #include <boost/intrusive/list.hpp>
> #include <string>
> #include <iostream>
>
> using namespace std;
>
> class animal
> {
> public:
> animal (string n, int l) : name{move(n)}, legs{l} {}
>
> string name;
> int legs;
> boost::intrusive::list_member_hook<> _animal_hook;
> };
>
> typedef boost::intrusive::member_hook<animal,
> boost::intrusive::list_member_hook<>, &animal::_animal_hook>
> AnimalHookOption;
>
> typedef boost::intrusive::list<animal, AnimalHookOption> Animals;
>
> void print_list (const Animals& elem)
> {
> for (const Animals::value_type& a : elem)
> cout << "A " << a.name << " has " << a.legs << " legs" << '\n';
> }
>
> int main()
> {
> animal a1{"dog", 4};
> animal a2{"spider", 6};
> animal a3{"budgie", 2};
> Animals animals;
>
> animals.push_back(a1);
> animals.push_back(a2);
> animals.push_back(a3);
> print_list (animals);
>
> return 0;
> }
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> https://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net