Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

What Is the Difference Between Structs and Classes in C++?

423.9K views
•
July 2, 2017
by
The Cherno
YouTube video player
What Is the Difference Between Structs and Classes in C++?

TL;DR

The difference between structs and classes in C++ lies in their default member visibility: members in a struct are public by default, while members in a class are private. Structs exist for backward compatibility with C, and personal programming style typically influences when to use one over the other.

Transcript

Hey, guys. My name is The Cherno and welcome back to my C++ series. This is going to be a really quick episode in which I'm just going to based answer the question What is the difference between a struct and a class in C++? The last time we talked about classes in General And we had a bit of a basic introduction to what classes actually were you gu... Read More

Key Insights

  • 👷 The only difference between a struct and a class in C++ is the default visibility of members.
  • 👨‍💻 The struct keyword exists in C++ for backward compatibility with C code.
  • 👨‍💻 Personal programming style and preference may dictate the usage of struct and class in code.
  • 👷 Inheritance should be used with classes, not structs.
  • 🥶 Structs are commonly used for plain old data (POD) structures that represent variables without much functionality.
  • 👨‍💻 The compatibility between C and C++ code can be maintained by using a define statement to replace all instances of the struct keyword with class.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: What is the difference between a struct and a class in C++?

The only difference between a struct and a class in C++ is the default visibility of members. In a struct, members are public by default, while in a class, members are private by default.

Q: Why does the struct keyword exist in C++?

The struct keyword exists in C++ for backward compatibility with C code. C code does not have classes, but it does have structures. Using the struct keyword allows C++ to maintain compatibility with C code.

Q: When should I use a struct instead of a class?

You can use a struct instead of a class when you want all of the members to be public by default and you don't want to explicitly write the word "public". It is typically used for plain old data (POD) structures that represent variables without much functionality.

Q: Can I use a struct and a class interchangeably in C++?

Yes, you can use a struct and a class interchangeably in C++. The only difference is the default visibility of members. You can choose to use either based on personal programming style and preference.

Key Insights:

  • The only difference between a struct and a class in C++ is the default visibility of members.
  • The struct keyword exists in C++ for backward compatibility with C code.
  • Personal programming style and preference may dictate the usage of struct and class in code.
  • Inheritance should be used with classes, not structs.
  • Structs are commonly used for plain old data (POD) structures that represent variables without much functionality.
  • The compatibility between C and C++ code can be maintained by using a define statement to replace all instances of the struct keyword with class.
  • Support for the C++ series can be shown by following The Cherno on Twitter and Instagram or supporting them on Patreon.

Summary & Key Takeaways

  • The main difference between a struct and a class in C++ is the default visibility of members. In a class, members are private by default, while in a struct, members are public by default.

  • The struct keyword exists in C++ for backward compatibility with C code, as C code does not have classes but does have structures.

  • The usage of struct and class in code may differ based on personal programming style, but there is no right or wrong answer.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from The Cherno 📚

What Are Pointers in C++ and How Do They Work? thumbnail
What Are Pointers in C++ and How Do They Work?
The Cherno
Welcome to OpenGL thumbnail
Welcome to OpenGL
The Cherno
The NEW Keyword in C++ thumbnail
The NEW Keyword in C++
The Cherno
GAME ENGINE DEVELOPER Reacts to UNREAL ENGINE 5 EARLY ACCESS thumbnail
GAME ENGINE DEVELOPER Reacts to UNREAL ENGINE 5 EARLY ACCESS
The Cherno
Maths | Game Engine series thumbnail
Maths | Game Engine series
The Cherno
How to DEBUG C++ in VISUAL STUDIO thumbnail
How to DEBUG C++ in VISUAL STUDIO
The Cherno

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots

Company

  • About us
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.