Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1016545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:33:54+00:00 2026-05-16T10:33:54+00:00

I am looking at the implementation of an API that I am using. I

  • 0

I am looking at the implementation of an API that I am using.

I noticed that a struct is inheriting from a class and I paused to ponder on it…

First, I didn’t see in the C++ manual I studied with that a struct could inherit from another struct:

struct A {};
struct B : public A {};

I guess that in such a case, struct B inherits from all the data in stuct A. Can we declare public/private members in a struct?

But I noticed this:

 class A {};
 struct B : public A {};  

From my online C++ manual:

A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

Is the above inheritance valid even if class A has some member functions? What happen to the functions when a struct inherit them? And what about the reverse: a class inheriting from a struct?

Practically speaking, I have this:

struct user_messages {
  std::list<std::string> messages;
};

And I used to iterate over it like this foreach message in user_messages.messages.

If I want to add member functions to my struct, can I change its declaration and “promote” it to a class, add functions, and still iterate over my user_messages.messages as I did before?

Obviously, I am still a newbie and I am still unclear how structs and classes interact with each other, what’s the practical difference between the two, and what the inheritance rules are…

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:33:55+00:00Added an answer on May 16, 2026 at 10:33 am

    Yes, struct can inherit from class in C++.

    In C++, classes and struct are the same except for their default behaviour with regards to inheritance and access levels of members.

    C++ class

    • Default Inheritance = private
    • Default Access Level for Member Variables and Functions = private

    C++ struct

    • Default Inheritance = public
    • Default Access Level for Member Variables and Functions = public
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a fast queue implementation in Java. I see that LinkedList
I'm looking for an API that can be accessed via C# implementation where I
I'm looking for implementation of IP Traceback using packet marking algorithm in C#? I
Im looking at this implementation of DCT using cuda: http://www.cse.nd.edu/courses/cse60881/www/source_code/dct8x8/dct8x8_kernel1.cu The part in question
I'm looking for an implementation of java.util.Map that has a method that will return
I'm using WCF, SQL Server and ADO.NET. I'm looking at two implementation options for
Looking at the previous implementation of a site that I'm working on, I can
A decompression API that I am using has the following API: Decode(Stream inStream,Stream outStream)
I am looking for a library/API that seperates strings by spaces an line-breaks to
I'm looking for implementation of log() and exp() functions provided in C library <math.h>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.