Class vs Struct | C++ (What's the Difference?)

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 เม.ย. 2023
  • Start your software dev career - calcur.tech/dev-fundamentals Be notified of new C/C++ course: calcur.tech/c-cpp-newsletter
    💯 FREE Courses (100+ hours) - calcur.tech/all-in-ones
    ⚛️ FREE React Course (20 hours) - calcur.tech/free-react-course
    ✅ Data Structures & Algorithms - calcur.tech/dsa-youtube
    ~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~
    ✉️ Newsletter - calcur.tech/newsletter
    📸 Instagram - / calebcurry
    🐦 Twitter - / calebcurry
    🔗 LinkedIn - / calebcurry
    ▶️ Subscribe - calcur.tech/subscribe
    👨🏻‍🎓 Courses - www.codebreakthrough.com
    ~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~
    ↪ My Amazon Store - www.amazon.com/shop/calebcurry
    🅿 Patreon - calcur.tech/patreon-calebcurry
    🅖 GitHub Sponsors - github.com/sponsors/CalebCurry
    Ⓟ Paypal - paypal.me/calcur
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 12

  • @codebreakthrough
    @codebreakthrough  ปีที่แล้ว +4

    Are there differences I forgot?
    Be notified of new C/C++ course: calcur.tech/c-cpp-newsletter
    💯 FREE Courses (100+ hours) - calcur.tech/all-in-ones

  • @AlexanderWeurding
    @AlexanderWeurding ปีที่แล้ว +23

    In C++, both classes and structs are used to define custom data types, and they share many similarities. However, there are a few key differences between them:
    Default member access: The default access level for members in a struct is "public", while the default for a class is "private". This means that members of a struct can be accessed directly from outside the struct, while members of a class cannot.
    Inheritance: A class can be inherited from another class or struct using the "class" keyword, while a struct can only be inherited from another struct.
    Member functions: A class can have member functions, which are functions that operate on the data members of the class. A struct can also have member functions, but they are not as commonly used.
    Constructors and destructors: A class can have constructors and destructors, which are special member functions that are called when an object is created or destroyed. A struct can also have constructors and destructors, but they are not as commonly used.
    In general, classes are used for more complex data types that require encapsulation and data abstraction, while structs are used for simpler data types that do not require as much abstraction or encapsulation. However, the choice between using a class or a struct ultimately depends on the specific needs of the program and the personal preferences of the programmer.

    • @pw.70
      @pw.70 11 หลายเดือนก่อน +1

      'Preference of the programmer' - wow! Now there's a grey area!

    • @frankhart2188
      @frankhart2188 9 หลายเดือนก่อน

      You forgot polymorphism i guess ;)

  • @uraymeiviar
    @uraymeiviar ปีที่แล้ว +4

    there are no difference, except the mistake that c++ allow struct to have similarr feature as class, they should keep struct as POD

  • @joshi1q2w3e
    @joshi1q2w3e 10 หลายเดือนก่อน +2

    Can you please make a beginner to advanced course on Go, because I still don’t understand, if you don’t use OOP in Go what do you use?
    I’m still a noob so don’t know everything. I’m used to Classes in Python.

  • @dastin7276
    @dastin7276 2 หลายเดือนก่อน

    Thank You. You are an excellent teacher.

  • @Fs-bc5fg
    @Fs-bc5fg ปีที่แล้ว

    Amazing, thanks

  • @ghsewar989
    @ghsewar989 2 หลายเดือนก่อน

    Thank you so much!

  • @pw.70
    @pw.70 11 หลายเดือนก่อน

    Isn't the primary difference by implication? Shouldn't programmers work to make structs immutable? I know this is the case with some other languages. Forgive me if I'm wrong, but I'm not a C++ developer.

  • @PandaXpress668
    @PandaXpress668 6 หลายเดือนก่อน

    What vscode theme is that?

  • @micahjacobson8533
    @micahjacobson8533 7 หลายเดือนก่อน

    Why is Child able to access a without making Parent public but Grandchild can’t?