Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1008277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:44:50+00:00 2026-05-16T08:44:50+00:00

I have a linked list structure: struct SomeLinkedList { const char* bar; int lots_of_interesting_stuff_in_here;

  • 0

I have a linked list structure:

struct SomeLinkedList
{
    const char* bar;
    int lots_of_interesting_stuff_in_here;
    DWORD foo;
    SomeLinkedList* pNext;
};

It is part of an existing API and I cannot change it.

I would like to add iterator support. The boost::iterator_facade<> library seemed ideal for the purpose.

class SomeIterator
    : public boost::iterator_facade< SomeIterator, 
                                     const SomeLinkedList, 
                                     boost::forward_traversal_tag >
{
public:
    SomeIterator() : node_( NULL ) {};

    explicit SomeIterator( const SomeLinkedList* p ) : node_( p ) {};

private:
    friend class boost::iterator_core_access;

    void increment() { node_ = node_->pNext; };

    bool equal( SomeIterator const& other ) const { /*some comparison*/; };

    SomeLinkedList const& dereference() const { return *node_; };

    SomeLinkedList const* node_;
}; // class SomeIterator

The goal is to be able to use it in standard library functions like std::for_each

void DoSomething( const SomeLinkedList* node );

SomeLinkedList* my_list = CreateLinkedList();
std::for_each( SomeIterator( my_list ), SomeIterator(), DoSomething );

Unfortunately, I’m getting an error saying it’s trying to pass the list by value rather than by pointer.

error C2664: 'void (const SomeLinkedList *)' : cannot convert parameter 1 from 'const SomeLinkedList' to 'const SomeLinkedList *'

How can I change SomeIterator to do to get this working correctly?

Thanks,
PaulH


Edit:
I’ve tried this:

class SomeIterator
    : public boost::iterator_facade< SomeIterator, 
                                     SomeLinkedList, 
                                     boost::forward_traversal_tag,
                                     SomeLinkedList* >
{
    // ...

but I get this complier error:

error C2664: 'boost::implicit_cast' : cannot convert parameter 1 from 'SomeLinkedList **' to 'boost::detail::operator_arrow_proxy<T>

Edit 2:

I’ve tried modifying the dereference type:

class SomeIterator
    : public boost::iterator_facade< SomeIterator, 
                                     const SomeLinkedList, 
                                     boost::forward_traversal_tag >
{
    // ...

    const SomeLinkedList* dereference() const { return node_; };

but, I get the original error:

error C2664: 'void (const SomeLinkedList *)' : cannot convert parameter 1 from 'const SomeLinkedList' to 'const SomeLinkedList *'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:44:50+00:00Added an answer on May 16, 2026 at 8:44 am

    When your iterator is dereferenced, it would return a const SomeLinkedList& however your DoSomething function is expecting a const SomeLinkedList*. Either alter the iterator to somehow return pointers when dereferenced or alter your DoSomething function.


    EDIT in response to further discussion:

    I haven’t actually used boost::iterator_facade myself, but looking at additional code you posted it appears you might not have changed all the necessary parts at the same time.

    Have you actually tried

    class SomeIterator
        : public boost::iterator_facade< SomeIterator, 
                                         SomeLinkedList, 
                                         boost::forward_traversal_tag,
                                         SomeLinkedList* >
    {
    

    and

    const SomeLinkedList* dereference() const { return node_; };
    

    together?

    Or if that doesn’t work, then how about:

    class SomeIterator
        : public boost::iterator_facade< SomeIterator, 
                                         SomeLinkedList*, 
                                         boost::forward_traversal_tag>
    {
    
    const SomeLinkedList* dereference() const { return node_; };
    

    Alternatively, as davka suggested in a comment, what about solving the pointer vs reference issue by making a wrapper around DoSomething? Such as:

    void DoSomethingWrapper( const SomeLinkedList& node )
    {
        DoSomething(&node);
    }
    

    In fact, you could probably even keep the wrapper the same name as the function it wraps and just let overloading rules take care of when the pointer or reference version gets called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following array structure (linked list): struct str_pair { char ip [50]
Suppose I have a following linked list structure: struct linked_list { struct linked_list *next;
Say you have a linked list structure in Java. It's made up of Nodes:
I have a Linked List and I want to implement a function: Random_Shuffle_List (struct
I have a singly-linked list containing 1 value in each element. struct listElement {
I have a self made data structure (for example linked list) that works well,
If I have a linked list structure, and I implement the clear() method as
I have a structure as struct Employee { char uName [255]; struct Employee *
I have a program which places structures in a linked list based on the
I have a linked list, which stores groups of settings for my application: typedef

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.