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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:17:43+00:00 2026-05-14T06:17:43+00:00

In one of my projects, I have some classes that represent entities that cannot

  • 0

In one of my projects, I have some classes that represent entities that cannot change once created, aka. immutable classes.

Example : A class RSAKey that represent a RSA key which only has const methods. There is no point changing the existing instance: if you need another one, you just create one.

My objects sometimes are heavy and I enforced the use of smart pointers to avoid deep copy.

So far, I have the following pattern for my classes:

class RSAKey : public boost::noncopyable, public boost::enable_shared_from_this<RSAKey>
{
    public:

    /**
     * \brief Some factory.
     * \param member A member value.
     * \return An instance.
     */
    static boost::shared_ptr<const RSAKey> createFromMember(int member);

    /**
     * \brief Get a member.
     * \return The member.
     */
    int getMember() const;

    private:

    /**
     * \brief Constructor.
     * \param member A member.
     */
    RSAKey(int member);

    /**
     * \brief Member.
     */
    const int m_member;
};

So you can only get a pointer (well, a smart pointer) to a const RSAKey. To me, it makes sense, because having a non-const reference to the instance is useless (it only has const methods).

Do you guys see any issue regarding this pattern ? Are immutable classes something common in C++ or did I just created a monster ?

Thank you for your advices !

  • 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-14T06:17:43+00:00Added an answer on May 14, 2026 at 6:17 am

    Looks good to me.

    Marking every object const from the factory obviates marking every data member const, but in this example there is only one anyway.

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

Sidebar

Related Questions

I have a handful of projects that all use one project for the data
I have a solution that contains two projects. One project is an ASP.NET Web
I want to be able to have two projects, one that contains production code
I have a script that appends some rows to a table. One of the
I have two projects in a workspace, one is a fancy application that is
I have 2 projects each one with its own unit test project, and one
I'm working in VS 2008 and have three projects in one solution. I'm debugging
I have several web application projects in one solution. When I start debugging one
We have similar code to the following in one of our projects. Can anyone
I have use IlMerge to merge all the dlls of my projects in one

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.