Topic: struct with constructor?
Author: rameshs@ix.netcom.com (Ramesh S)
Date: 1995/07/31 Raw View
In article <3v2edj$n6u@dub-news-svc-6.compuserve.com>, 71754.2053@compuserve.com (Wayne Conrad) says:
>
>>Can I declare a constructor and a destructor for a structure (struct {})?
>
>Yep.
>
>The difference between a struct and a class in C++ is very simple. In
>a class, members start out being private unless you say otherwise with
>the "public:" or "protected:" keywords. In a struct, members start
>out being public unless you say otherwise with the "private:" or
>"protected:" keywords.
>
>As far as I know, that's the only difference between a class and a
>struct.
>
The same reason holds good for the derivation signature also.
- Ramesh
Author: Ralf Boecker <boecker@hrz.uni-kassel.de>
Date: 1995/07/28 Raw View
No problem.
But be aware that then You can no longer initialize it
by using the ={...} list.
So you should rather declare it as class with private members at all.
A technique I sometimes use when I want to use c-tor as well as aggregate initalization
is to declare a struct as Base with all the member functions I need
and then derive a special class supplying the constructor.
But this should only be done with very simple and straightforward classes
(e.g. PointXY or so) since the public members in the struct
violate the OOP information hiding principle.
--
*** Dipl.-Ing. Ralf Boecker Universitaet GH Kassel ***
*** eMail: boecker@hrz.uni-kassel.de FB 16 - Elektrotechnik ***
*** Tel: (+49)561/804-6404 Wilhelmshoeher Allee 73 ***
*** Fax: (+49)561/804-6360 D-34121 Kassel (Germany) ***
Author: h.b.furuseth@usit.uio.no (Hallvard B Furuseth)
Date: 1995/07/25 Raw View
In article <3uvqfv$c74@taiwan.informatik.uni-rostock.de> schmitz@.egd.egd.igd.fhg.de (Christian Schmitz) writes:
> Can I declare a constructor and a destructor for a structure (struct {})?
Sure. `struct' simply means `class' with `public:' default member access.
Check any C++ book.
--
Hallvard
Author: Etay Bogner <ebogner@ird.scitex.com>
Date: 1995/07/26 Raw View
Also, the derivation behaves like this :
class A : B {} => A is privatly derived from B
and
struct A : B {} => A is publicly derived from B
-- Etay Bogner,
-- ebogner@ird.scitex.com ( OLD ),
-- Etay_Bogner@mail.stil.scitex.com,
-- Scitex Corp.
-- Israel.
Author: schmitz@.egd.egd.igd.fhg.de (Christian Schmitz)
Date: 1995/07/24 Raw View
Can I declare a constructor and a destructor for a structure (struct {})?
Author: 71754.2053@compuserve.com (Wayne Conrad)
Date: 1995/07/25 Raw View
>Can I declare a constructor and a destructor for a structure (struct {})?
Yep.
The difference between a struct and a class in C++ is very simple. In
a class, members start out being private unless you say otherwise with
the "public:" or "protected:" keywords. In a struct, members start
out being public unless you say otherwise with the "private:" or
"protected:" keywords.
As far as I know, that's the only difference between a class and a
struct.