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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:50:12+00:00 2026-06-05T22:50:12+00:00

I would like my c++ code to be as encapsulated as i can is

  • 0

I would like my c++ code to be as encapsulated as i can is this manner of return the iterators is ok?

const map<string,bool>::iterator getFollowers() {

        return followers.begin();

    }

    const map<string,bool>::iterator getFollowing() {

        return following.begin();

    }

the full code:

#ifndef twitClient_twitUser_h
#define twitClient_twitUser_h

#include <map>
#include <iostream>
#include <string>

using namespace std;
class user {
    string username;
    map<string,bool> followers;
    map<string,bool> following;
    string name;


public:

    user(string username):username(username) {
        followers [username] = false;
        following [username] = false;
    }

    bool removeFollower (string friendName);
    bool addFollower(string friendName);
    bool stopFollowing(string friendName);
    bool startFollowing(string friendName);

    const map<string,bool>::iterator getFollowers() {

        return followers.begin();

    }

    const map<string,bool>::iterator getFollowing() {

        return following.begin();

    }


};
  • 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-05T22:50:14+00:00Added an answer on June 5, 2026 at 10:50 pm

    There’s nothong wrong with your approach, except that you may want to add const access methods too, foe example

    map<string,bool>::const_iterator getFollowers() const;
    

    Plus you want to add access to the end() iterators too.

    Concerning encapsulation, you encapsulate the map, but your clients are exposed to map<string, bool>::iterator. There’s a very interesting article about hiding those dependencies here. It is by no means trivial, but it is still worth considering.

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

Sidebar

Related Questions

I would like to execute code sequentially in an NSOperation. This can be easily
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
Problem: I would like to share code between multiple assemblies. This shared code will
I would like to know the code which can enable me to get a
I would like to be able to do something like (psuedo-code): if (classAvailable) {
I'm searching for the cleanest solution here. I would like to code a stored
I have a simple model from simulink and I would like to generate code
Would like to know the c# code to actually retrieve the IP type: Static
I would like to inspect any code changes after doing a git pull .
I would like to have my Python code start a Python interactive console (REPL)

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.