|
Boost Users : |
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2021-09-07 15:33:22
>
> 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 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