Base struct instead of class

  • Thread starter Marcin Vorbrodt
  • Start date
J

jeffc

Mike Smith said:
Or vice versa - one could argue that the "class" keyword was never
necessary at all, whereas "struct", of course, was already pre-existing
in C.

Or, since the meaning of struct has changed from C, one could argue that
struct shouldn't do anything different from what it did in C, but only the
new keyword class should be used to implement classes.
 
D

Dave Theese

When inheriting, if you don't specify public, inherited or private, the
No, it doesn't work that way. It doesn't matter whether the class you are
inheritting from was defined with struct or class. What matters is the key
used to define the derived class.

struct X; // or class X; it doesn't matter

struct Y : X { } ; // Public inheritance
class Y : X { } ; // Private inheritance.


Nope, you just have to make sure you put in enough public keys

struct Y : X { ...
is equivielent to
class Y : public X {
public: ...

Oh geez, you are absolutely right. Public vs. private by default depends on
the derived class, not the base class. 11.2.2 spells this out...

Thx for setting it straight!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top