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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:42:50+00:00 2026-05-14T01:42:50+00:00

Is it ok to have public data members in a C++ class/struct in certain

  • 0

Is it ok to have public data members in a C++ class/struct in certain particular situations?
How would that go along with inheritance?
I’ve read opinions on the matter, some stated already here

practices on when to implement accessors on private member variables rather than making them public
Accessors vs. public members

or in books/articles (Stroustrup, Meyers) but I’m still a little bit in the shade.

I have some configuration blocks that I read from a file (integers, bools, floats) and
I need to place them into a structure for later use. I don’t want to expose these externally just use them inside another class (I actually do want to pass these config parameters to another class but don’t want to expose them through a public API).

The fact is that I have many such config parameters (15 or so) and writing getters and setters seems an unnecessary overhead. Also I have more than one configuration block and these are sharing some of the parameters. Making a struct with all the data members public and then subclassing does not feel right. What’s the best way to tackle that situation?
Does making a big struct to cover all parameters provide an acceptable compromise (I
would have to leave some of these set to their default values for blocks that do not use them)?

  • 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-14T01:42:51+00:00Added an answer on May 14, 2026 at 1:42 am

    If you have a data structure that isn’t intended to have behaviour but genuinely is nothing more than a pure struct in the C sense, particularly if each instance of it is only used internally to the implementation of other “proper” classes, then it is fine to make it a struct and have public fields. After all, as you’ve pointed out, once you’ve given it get/set accessor functions for every field then you’re back to the logical equivalent of public data anyway.

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

Sidebar

Related Questions

Let's say I have data structures that're something like this: Public Class AttendenceRecord Public
Suppose I have some per-class data: (AandB.h) class A { public: static Persister* getPersister();
Here is the domain that I wish to have: public class Person { public
i have this in my BlogRepository public IQueryable<Subnus.MVC.Data.Model.Post> GetPosts() { var query = from
Let's say we have public interface ITimestampProvider { DateTime GetTimestamp(); } and a class
I'd like to find a few large .NET projects that have public source code
I have a public facing website that has been receiving a number of SQL
Here I have: Public Structure MyStruct Public Name as String Public Content as String
I have a public property set in my form of type ListE<T> where: public
I have this: public string Log { get { return log; } protected set

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.