Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Why struct instead of class?
Why struct instead of class? [message #21815] Sat, 06 June 2009 06:47 Go to next message
jeremy_c is currently offline  jeremy_c
Messages: 175
Registered: August 2007
Location: Ohio, USA
Experienced Member
Why do the example use struct instead of class? i.e.

struct MyAppWindow : TopWindow {

    virtual void Paint(Draw& w) {

        w.DrawRect(GetSize(), SWhite);

        w.DrawText(20, 20, "Hello world!", Arial(30), Magenta);

    }

    

    MyAppWindow() {

        Title("My application").Zoomable().Sizeable();

    }

};


Jeremy
Re: Why struct instead of class? [message #21817 is a reply to message #21815] Sat, 06 June 2009 17:52 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Well in modern C++ the difference between struct and class is pretty much trivial and related to default access rights: members in structs are public by default and members in classes are private by default.

C++ has a lot of duplicate features, so I tend to allays use only class to avoid it. But it makes no difference, use the one you like better, just don't mix and match in inheritance trees Smile.
Re: Why struct instead of class? [message #21825 is a reply to message #21815] Sun, 07 June 2009 21:46 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
jeremy_c wrote on Sat, 06 June 2009 00:47

Why do the example use struct instead of class? i.e.

struct MyAppWindow : TopWindow {

    virtual void Paint(Draw& w) {

        w.DrawRect(GetSize(), SWhite);

        w.DrawText(20, 20, "Hello world!", Arial(30), Magenta);

    }

    

    MyAppWindow() {

        Title("My application").Zoomable().Sizeable();

    }

};


Jeremy



Because I am lazy to write "public" for "final use" classes:)

I mean, access control is important for reusable classes. But if I am writing concrete app, I usually do not bother using access control as chances that class is going to be reused by other code is nil.

Mirek
Previous Topic: Heap Leaks Detected
Next Topic: Keyboard shortcut
Goto Forum:
  


Current Time: Wed Apr 24 10:36:15 CEST 2024

Total time taken to generate the page: 0.02511 seconds