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 6618665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:51:51+00:00 2026-05-25T20:51:51+00:00

How to call class member function using std::for_each Here is what my class is.

  • 0

How to call class member function using std::for_each
Here is what my class is.

template <typename _TyG>
class Graph {
private:        
public:
    typedef typename Vertex<_TyG>                           VertexType;
    typedef typename std::set<VertexType>                   GraphStorage;
    typedef typename GraphStorage::iterator                 GraphStorageItr;
    typedef typename GraphStorage::const_iterator           GraphStorageConstItr;

    typedef typename std::list<VertexType *>                AdjListType;
    typedef typename AdjListType::iterator                  AdjListTypeItr;
    typedef typename AdjListType::const_iterator            AdjListTypeConstItr;

    typedef typename std::map<  VertexType*, 
                                AdjListType, 
                                CompareIterator<VertexType*> >  GraphType;

    typedef typename GraphType::iterator                    GraphTypeItr;
    typedef typename GraphType::const_iterator              GraphTypeConstItr;

void _init_not_visited(GraphTypeItr inItr) {
}
void DepthFirstSearch() {
        std::for_each(m_Graph.begin(), m_Graph.end(), std::bind2nd(std::mem_fun(&Graph::_init_not_visited),this));
    }
}

What I want is to pass iterator to _init_not_visited. But I am confuse on how to use std::for_each, current code is giving me compilation error.

  • 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-25T20:51:52+00:00Added an answer on May 25, 2026 at 8:51 pm

    I do not think you can do what you want to do with std::for_each. As std::for_each calls the given function on each value in the sequence and not each iterator position in the sequence. std::for_each might look like:

    template <class iter_t, class fn_t>
    fn_t for_each(iter_t first iter_t const last, fn_t fn)
    {
        for (; first != last; ++first)
            fn(*first);
        return fn;
    }
    

    You can either write your own for_each_iter such as:

    template <class iter_t, class fn_t>
    fn_t for_each_iter(iter_t first, iter_t const last, fn_t fn)
    {
        for (; first != last; ++first) {
            fn(first);
        }
    
        return fn;
    }
    

    Or change _init_not_visited() to take GraphType::value_type instead of GraphTypeItr. Assuming that you can still write the function with that argument.

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

Sidebar

Related Questions

I am using a std::for_each loop on a local variable of a member function
I have class with member functions: typedef std::function<bool (const std::string &)> InsertFunction; bool insertSourceFile(
I have a templated class like this: template <typename T> class AguiEvent { std::vector<std::tr1::function<void(T,
I'm getting a Call to a member function process_data() on a non-object in page.class.php
I need to call function whenever class is created using new. Currently I need
I've been trying to call the overloaded table::scan_index(std::string, ...) member function without success. For
Consider the following program: #include <iostream> #include <algorithm> using namespace std; template<class T> struct
code: #include<iostream> using namespace std; template<class T, int N> class point { T coordinate[N];
#include<iostream> using namespace std; class base { protected: int a; public: base(int i) {
What does it mean to call a class like this: class Example { public:

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.