Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
#1: When to Use a struct vs
Class
#6: How would you count
the occurrences of a string
within a string?
#11: Encrypt/Decryp...
• structs are value types that can contain data and functions
• structs are value types and do not require heap allocation...
• With classes, multiple variables may have a reference to the same object
• It is possible for operations on one variable...
When to use a structure vs classes in c++
Upcoming SlideShare
Loading in …5
×

When to use a structure vs classes in c++

This is a presentation for c++ learning students . After watching this presentation you will learn when to use a structure vs classes in c++ .

  • Login to see the comments

When to use a structure vs classes in c++

  1. 1. #1: When to Use a struct vs Class #6: How would you count the occurrences of a string within a string? #11: Encrypt/Decrypt a String in .NET #16: How do I Make a Texbox that Only Accepts Numbers? #2: How Does One Parse XML Files? #7: How to Check if a Number is a Power of 2 #12: How do I Get the Index of the Current Iteration of a foreach Loop? #17: How do I Round a Decimal Value to 2 Places for Output? #3: What is the Difference between String and string #8: C# Loop – break vs continue #13: How to Get My Own IP address in C# #18: Remove Duplicates from an Array #4: How do I get the Application’s Path in a C# Console App? #9: Difference Between abstract and virtual functions #14: How do I Calculate Someone’s Age in C#? #19: How do I Sort a Dictionary by Value? #5: Calling base Constructor in C# #10: Difference Between ref and out Keywords #15: How do I get the String Value of an enum? #20: How Can I Return Multiple Values From a Function in C#?
  2. 2. • structs are value types that can contain data and functions • structs are value types and do not require heap allocation. • structs directly store their data in the struct, classes store a reference to a dynamically allocated object. • structs are useful for small data structures • structs can affect performance • Constructors are invoked with the new operator, but that does not allocate memory on the heap • A struct constructor simply returns the struct value itself (typically in a temporary location on the stack), and this value is then copied as necessary
  3. 3. • With classes, multiple variables may have a reference to the same object • It is possible for operations on one variable to affect the object referenced by the other variable. • With structs, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other. • structs do not support user-specified inheritance, and they implicitly inherit from type object

×