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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:16:18+00:00 2026-06-02T00:16:18+00:00

If my understanding is correct, the following semantics apply to structs and classes in

  • 0

If my understanding is correct, the following semantics apply to structs and classes in C++, C# and D:

        struct          class
----------------------------------
C++     stack/heap      stack/heap
        value/reference value/reference

C# / D  stack           heap
        value           reference

I.e., in C++ there is no semantic difference between structs and classes (apart from the default public / private access). In contrast, C# and D structs have value semantics and stack allocation (at least by default), whereas C# and D classes have reference semantics and heap allocation.

My question is: would it be good C++ style to mimic this difference by using the struct keyword exclusively for all entities with value semantics, and the class keyword exclusively for all entities with reference semantics?

It would of course be a self-discipline tool not enforced by the compiler, but it could improve code readibility, especially for reviewers with C# / D backgrounds. OTOH, the current idiom in C++ seems to be to only use the struct keyword for simple entities such as pure POD aggregates and template metafunctions only, so it could be confusing for C++ programmers.

  • 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-02T00:16:20+00:00Added an answer on June 2, 2026 at 12:16 am

    If that were the only relevant distinction, it might make sense. In
    practice, there’s much more to it than that. In C++, it’s very frequent
    for objects with real behavior (and which don’t support copy) to be
    allocated on the stack; it also occurs from time to time that pure data
    containers be allocated dynamically. C# and D are confounding two
    orthogonal distinctions: arbitrary object lifetime vs. object lifetime
    linked to scope, and whether the object has value semantics or not.
    While it’s true that these two distinctions do coincide for some types,
    it’s not an absolute rule, and imposing it at a language level creates a
    straight jacket which at times prevents the use of the cleanest and most
    natural solution.

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

Sidebar

Related Questions

Is my understanding correct, that the following class and table design is not possible
I'm new to Symfony. Is my understanding correct that the User class is actually
I often get doubt on these two phases. The following is my understanding: Apply
Given the following code without considering friendship between two classes: class OutSideClass { ...
correct me if any of my following current understanding of c++ is wrong: C++
For the following code snippet, is my understanding of $label = $classifier->{result}->{forcast}->[$i]->{label}; correct? 1)
Is the following code Correct?As far as my understanding,it should not work properly,but on
If my understanding is correct, you can't actually look at messages in the rabbit
I want to verify that my understanding is correct. This kind of thing is
Ramaze.start :port => 80 If my understanding is correct, the line above is 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.