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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:24:20+00:00 2026-06-03T23:24:20+00:00

I have a problem in const manipulation of my variables. I have simplified the

  • 0

I have a problem in const manipulation of my variables. I have simplified the problem into the following program:

#include <string>
#include <iostream>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/sequenced_index.hpp>

using boost::multi_index::multi_index_container;
using boost::multi_index::ordered_non_unique;
using boost::multi_index::ordered_unique;
using boost::multi_index::indexed_by;
using boost::multi_index::member;
using boost::multi_index::sequenced;

struct employee_entry
{
   employee_entry( const std::string& first,
                   const std::string& last,
                   long id):
                   first_name_(first),
                   last_name_(last),
                   id_(id)
   {}
   std::string first_name_;
   std::string last_name_;
   long id_;
};


typedef multi_index_container<
employee_entry, indexed_by<
   ordered_unique<member<employee_entry, std::string , &employee_entry::first_name_> >
   , ordered_non_unique<member<employee_entry, std::string , &employee_entry::last_name_> >
   , ordered_non_unique<member<employee_entry, long , &employee_entry::id_> >
    ,sequenced<>
   >
> employee_set;

using boost::multi_index::nth_index;
using boost::multi_index::get;

typedef nth_index<employee_set, 0>::type first_name_view;

class A
{
private:
    employee_set m_employees;
public:
    first_name_view& get()
    {
        return m_employees.get<0>();
    }

};


int main()
{
    A *a = new A;
   first_name_view& fnv = a->get();

   fnv.insert(employee_entry("John", "Smith", 110));
   fnv.insert(employee_entry("John1", "Hunk", 97));

   const A *a1 = a;
   first_name_view& fdv = a1->get();

   for(first_name_view::iterator it = fdv.begin(), it_end(fdv.end()); it != it_end; ++it)
   {
      //....
   }
   return 0;
}

assuming variable a1 MUST be constant, I get compilation error as:

$ c++ dr2.cpp 
dr2.cpp: In function ‘int main()’:
dr2.cpp:66:35: error: passing ‘const A’ as ‘this’ argument of ‘first_name_view& A::get()’ discards qualifiers [-fpermissive]

I appreciate if you kindly help me solve the issue.
Thanks you

  • 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-03T23:24:22+00:00Added an answer on June 3, 2026 at 11:24 pm

    You need a const overload of the get() function, which you can call on a const object; it must return a const reference since it can only call the const overload of employee_set::get():

    class A
    {
    private:
        employee_set m_employees;
    public:
        first_name_view& get()
        {
            return m_employees.get<0>();
        }
        first_name_view const & get() const   //< Add this
        {
            return m_employees.get<0>();
        }
    };
    

    and then you need to use that to initialise a const reference:

    first_name_view const & fdv = a1->get();
                 // ^^^^^ add this
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem with data transfert in boost::asio. with the following code :
I have one problem. i have dep. prop. of type List.. public const string
I have a problem initializing an array whose size is defined as extern const.
I have problem while loading data into html select when users press or click
I have a problem regarding 'static const' member initialization. In a templated class I
I have a problem with Visual Studio 2008 concerning virtual inheritance. Consider the following
I have problem with deserialization of json string, because string is bad format. For
I have a problem using AVURLAsset. NSString * const kContentURL = @ http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8; ...
Hi I have problem in code that the following code retuning the error that
I have a problem using the STL containers in c++ function 1; void addStudent(const

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.