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

  • Home
  • SEARCH
  • 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 8878697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:46:31+00:00 2026-06-14T19:46:31+00:00

I have made a program using boost::variant that somehow isn’t const correct. error: passing

  • 0

I have made a program using boost::variant that somehow isn’t const correct.

error: passing ‘const CompareTitle’ as ‘this’ argument of ‘bool CompareTitle::operator()(const T1&, const T2&) [with T1 = TestSeizoen, T2 = TestSeizoen]’ discards qualifiers [-fpermissive]

same error for [T1=TestFilm, T2 = TestSeizoen] and so on.

This is the code:

#include <iostream>
#include <vector>
#include "boost/variant.hpp"

using namespace std;

class TestFilm{
private:
   string titel_;
public:
   TestFilm(const string& titel): titel_(titel){};
   const string titel() const {return titel_;};
};

class TestSeizoen{
private:
    string titel_;
public:
    TestSeizoen(const string& titel): titel_(titel){};
    const string titel() const {return titel_;};
};


struct CompareTitle: boost::static_visitor<bool>{
  template <typename T1, typename T2>
  bool operator() (const T1& t1 , const T2& t2){
     return t1.titel() == t2.titel();
  }
};


int main() {
   typedef boost::variant<TestFilm,TestSeizoen> var;
   vector <var> vec;
       TestFilm film1("titel1");
   vec.push_back(film1);
   TestSeizoen seizoen1("titel2");
   vec.push_back(seizoen1);
   vector<var>::iterator it;
   bool compare = boost::apply_visitor(CompareTitle(),*vec.begin(),*(vec.begin()+1));
   return 0;
}

I tried to make operator() a const member function but this didn’t solve the problem. Can anybody help? I can provide more information if needed. Thanks in advance.

  • 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-06-14T19:46:32+00:00Added an answer on June 14, 2026 at 7:46 pm

    I think you need to promise that operator() won’t change the struct members, i.e.:

    bool operator() (const T1& t1 , const T2& t2) const {
    ...
    }
    

    This compiles for me (with GCC 4.4.5).

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

Sidebar

Related Questions

I have a made a simple program that reproduces the problem: #include <boost/archive/text_oarchive.hpp> #include
i have made a small opengl program using the d programming language. what i
I have made a program that scans rss feeds. This same program creates feeds
I have made a script that uses a program called Diascope, its a video
I have made a batch file that call another one program.bat , the first
I have made a Windows Service that gets installed in a c:\Program Files\My Service
i have made a program in C using the gcc compiler. Right now it
If I made a program that stores strings on a text file using the
I have made my custom jar file and compiled it using path C:\Program Files\Java\jdk1.7.0_04\bin;%path%
I have made a simple, test program to experiment using classes. It creates a

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.