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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:37:00+00:00 2026-05-21T18:37:00+00:00

I am a bit confused on the application of boost::static_visitor for variants and structures.

  • 0

I am a bit confused on the application of boost::static_visitor for
variants and structures. I have included a test case below. For
the commented out sections in “s_visitor”, I do not understand why
the following error message occurs or how to fix it:

apply_visitor_unary.hpp:72: error: ‘struct s1’ has no member named ‘apply_visitor’

#include "boost/variant.hpp"
#include "iostream"

struct s1 {
  int val;

  s1(int a) : val(a) {}
};

struct s2 {
  s1  s;
  int val;

  s2(int a, int b) : s(a), val(b) {}
};

struct s_visitor : public boost::static_visitor<>
{
    void operator()(int & i) const
    {
        std::cout << "int" << std::endl;
    }

    void operator()(s1 & s) const
    {
        std::cout << "s1" << std::endl;
    }

    void operator()(s2 & s) const
    {
        std::cout << "s2" << std::endl;
        // -> following 'struct s1' has no member apply_visitor
        // boost::apply_visitor(s_visitor(), s.s);
        // -> following 'struct s1' has no member apply_visitor
        // boost::apply_visitor(*this, s.s);
        s_visitor v;
        v(s.s);
    }
};

int main(int argc, char **argv)
{
  boost::variant< int, s1, s2 > v;
  s1 a(1);
  s2 b(2, 3);

  v = a;
  boost::apply_visitor(s_visitor(), v);

  v = b;
  boost::apply_visitor(s_visitor(), v);

  return 0;
}

Thanks for any help and/or clarification.

  • 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-21T18:37:01+00:00Added an answer on May 21, 2026 at 6:37 pm

    You get compile errors for both of the commented-out lines because you are passing in an “s1” where a boost::variant is expected. At that point in the code, however, you know the exact type, so you don’t need to do variant visitation, you can just do whatever you want with the value of type s1.

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

Sidebar

Related Questions

I'm a bit confused on setting up the boost test library. Here is my
I am a bit confused over what is happening. I have my application using
I am a bit confused: We have a chat application that has a requirement
I am a bit confused about this. If you're building a distributed application, which
I'm creating a simple Windows Forms application with NHibernate and I'm a bit confused
Bit confused here, I have an on-demand instance but do I get charged even
I'm a bit confused with NetBeans (versions 6.5 and 6.7). I have a NetBeans
Actually i m little bit confused in Intent. Suppose i have three activities. A,b,c
I am a bit confused on how to develop my application: I was thinking
I'm a bit confused on url writing in .htaccess and have a question about

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.