Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [struct]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
27 votes
9 answers
7k views

Is it a security vulnerability to declare class members as public?

I have always wondered whether public, protected, and private has security implications post compilation. Hypothetically: class Foo { public: int m_Foo; // Completely vulnerable and dangerous ...
user avatar
  • 3,319
9 votes
1 answer
1k views

Why List<T>.Enumerator is struct?

During my investigations of List<T> enumeration I noticed List<T>.Enumerator is struct. In opposite for instance to System.Array.SZArrayEnumerator or System.SZArrayHelper....
user avatar
  • 268
5 votes
3 answers
647 views

Struct or class for wrapping an int when 0 isn't a valid value

I have a business object which is basically a wrapper around a value of type int. There are some constraints for the value/object: Not every value in int's range is valid1 The valid values are not a ...
user avatar
-1 votes
1 answer
230 views

Few unusual C/C++ declarations

I came across this Enum and Struct declarations in a project supposedly done by an expert. The declarations / definitions are little different than what im used to so far. enum EnumKeys { KEY_MENU ,...
user avatar
  • 117
6 votes
0 answers
321 views

Rust and lifetime elision rules for structs?

In the Rust documentation, under the structs section, they give this example of how structs need lifetimes when they contain references: struct Foo<'a> { x: &'a i32, } because We ...
user avatar
182 votes
5 answers
175k views

When do you use a struct instead of a class? [closed]

What are your rules of thumb for when to use structs vs. classes? I'm thinking of the C# definition of those terms but if your language has similar concepts I'd like to hear your opinion as well. I ...
user avatar