Unions, structure and inheritance

D

doublemaster007

1) Can the unions and structures be inherited?
2) Can Unions and structures have virtual function?
 
K

Kai-Uwe Bux

1) Can the unions and structures be inherited?

unions: no (and they cannot inherit either)
structs: yes (and they can inherit, too)
2) Can Unions and structures have virtual function?

unions: no
structs: yes


Best

Kai-Uwe Bux
 
J

Juha Nieminen

Kai-Uwe Bux said:
unions: no (and they cannot inherit either)
structs: yes (and they can inherit, too)


unions: no
structs: yes

As an additional note, there's basically no difference between a
struct and a class in C++, except that in a struct all members are
public by default while in a class they are private by default (ie. when
there's no explicit "public:" or "private:" specifier).

I think that you can even pre-declare a type as a struct and implement
it as a class, and it will work at least in some compilers. I don't
know, however, if that's standard behavior. (Is it?)
 
A

Alf P. Steinbach

* Juha Nieminen:
I think that you can even pre-declare a type as a struct and implement
it as a class, and it will work at least in some compilers. I don't
know, however, if that's standard behavior. (Is it?)

Yes it is, but at least MSVC warns about it.

At the syntax level there is a difference between 'class' and 'struct', namely
in template formal parameter definitions, where you can (and in the case of a
parameter that itself is a template must) use the keyword 'class'.

Bjarne wrote a book about the rationale of the C++ design decisions, and when or
if I get rich I think that's one book I'll definitely buy. For now though, it's
mostly thrillers and science fiction. Actually now re-reading my old library,
currently Nancy Kress "Beggars in Spain" (interestingly the plot starts in
"future" 2008 :) (but as an even more off-topic note, re-reading old Asimov and
Heinlein, as of 2008 starships, naturally, had all-male crews, so even though
programming hasn't changed much since 1950 and Windows is still struggling with
national character support we've come some way regarding gender issues) ).


Cheers & hth.,

- Alf
 
D

doublemaster007

  As an additional note, there's basically no difference between a
struct and a class in C++, except that in a struct all members are
public by default while in a class they are private by default (ie. when
there's no explicit "public:" or "private:" specifier).

  I think that you can even pre-declare a type as a struct and implement
it as a class, and it will work at least in some compilers. I don't
know, however, if that's standard behavior. (Is it?)

Thanks for all...
Pre declare??? YOu mean..forword declaration??
 

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,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top