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 6149887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:31:48+00:00 2026-05-23T19:31:48+00:00

I was recently doing some Windows Api coding (still doing it). And I was

  • 0

I was recently doing some Windows Api coding (still doing it). And I was trying to find the best way to wrap the WNDCLASSEX into a C++ class, when I had this crazy idea, the WNDCLASSEX is a struct right? (even though it is written in c) and in C++ structs are treated as classes, so why don’t I declare my WinCLass as a derivative of WNDCLASSEX , so I tried:

 class WinClass : protected WNDCLASSEX

And it worked! Then I tried using it with SDL structs but those worked too. But some structs(especially SDL ones) either don’t compile or cause unexplained runtime errors when I derive classes from them. So my question:
Is this kind of C struct use recommended? Is it actually used by pros, or is it just a lame hack? Should I use for my wrapppers or apps, or will this just introduce unexplained bugs?

  • 1 1 Answer
  • 0 Views
  • 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-23T19:31:49+00:00Added an answer on May 23, 2026 at 7:31 pm

    The only difference between a class and a structure in C++ is that of Access specifiers.

    For classes the access specifier is private by default.
    For structures the access specifier is public by default.

    This means if you have a class deriving from other class/struct it will be private inheritance by default &
    If you have a structure deriving from other class/structure it will be a public inheritance by default.

    One problem though is that since for structure default access specifier is public, they may expose members that maybe should not be exposed to deriving classes. The entire encapsulation has a whole new dimension in this sense. Ofcourse, You If you can change the access specifiers inside the structure which you intend to use as Base, then it is possible to avoid the problem, but it may not be possible because that might affect how the structure is being used from other parts of the program.

    EDIT:
    Through the comments, I have a fair idea now, what errors you are referring to, the errors are not specifically because you are deriving from a structure but because you are misunderstanding the rules of Inheritance & Access specifiers.

    Here is a sample program for demonstration:

    #include<iostream>
    
    using namespace std;
    
    struct FirstStruct
    {
        private:
            int a;
        public:
            int b;
            FirstStruct():a(10),b(20),c(30)
            {
            }
        protected:
            int c;
    };
    
    class MyClass:protected FirstStruct
    {
        public: 
            int i;
            MyClass():i(40),j(50),k(60)
            {
            }
            void doSomething()
            {
                a = 100; //private in Base is not accessible in Derived
                b = 100; //Accessible
                c = 100; //Accessible  
    
                i = 100; //Accessible  
                b = 100; //Accessible  
                c = 100; //Accessible  
            }
        private:
            int j;
        protected:
            int k; 
    };
    
    int main()
    {
        MyClass obj;
        obj.i = 100; //Accessible
        obj.j = 100; //Error Cannot be Accessed, j is private member
        obj.k = 100; //Error Cannot be Accessed, k is protected member
        obj.a = 100; //Error Cannot be Accessed, a is private member in Base Class
        obj.b = 100; //Error Cannot be Accessed; 
                     //b is protected member of MyClass, because of protected Inheritance
        obj.c = 100; //Error Cannot be Accessed; 
                     //same reason as b
    
    
        obj.doSomething();
    
        return 0;
    }
    

    You can check running the same here at Ideone.
    You will notice even If you change the type of the Base from struct FirstStruct to class FirstStruct here you get the same errors(nothing more nothing less).

    Suggest you to have a look at this answer here, to clear your understanding on Inheritance and Access specifier rules.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Java experience and recently am doing some C++ coding. My question is
I've been doing some tutorials, and a lot of reading on Windows Workflow recently,
I've been looking into Varnish recently and doing some heavy Google searching. We've recently
I recently ran up against a wall doing some bash shell programming where an
I've been doing some WPF development for the last few months, and I've recently
One thing I've started doing more often recently is retrieving some data at the
I have recently been doing a bit of investigation into the different types of
I've recently been doing a lot of Objective-C programming, and just got back into
Recently I've been doing lots of weekend coding, and have began to really need
I've been doing some pagination recently and used the following: if ( $totalPages >

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.