Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Objective-C Basics (Retired) Pointers and Memory Structs

Laurie Gray
Laurie Gray
23,119 Points

Is a struct kind of like an Object in this example?

I have some javascript experience and am trying to grasp this. Is the struct here like an object from js?

2 Answers

Structs are a C++ construct. In C++, the only difference between structs and classes is that the members in structs are publicly visible by default (while in classes they are private by default).

That being said, most of the times structs are used as pure data containers. If you want to put a bunch of data together (with no methods which act on them) you may want to use a struct.

When you want to add some methods that act upon the data and you also want to have some internal representation that pertains to the said data (you may also want to hide the internal representation from the rest of your system) you will most likely want to use a class definition.

NOTE: you are allowed to define methods inside a struct in C++, but it is not a widely used practice due to the default public member access.

Laurie Gray
Laurie Gray
23,119 Points

Thanks Andrei, Im struggling with this language but its going to be worth it!