1

Topic: Difference Class from Struct

Are at first sight almost identical?
When correctly to use Class and when Struct?

2

Re: Difference Class from Struct

semen.s.semen;
There is no difference besides that in struct all members by default public, and in class - by default private.

3

Re: Difference Class from Struct

struct it is convenient to use when at you the code in style of a C - i.e. there are no methods/designers.

4

Re: Difference Class from Struct

Anatoly Moskovsky, there is one more small difference - presence/absence by default the pointer on VTBL.

5

Re: Difference Class from Struct

rdb_dev wrote:

Anatoly Moskovsky, there is one more small difference - presence/absence by default the pointer on VTBL.

Tell  on more detailed

6

Re: Difference Class from Struct

Anatoly Moskovsky wrote:

struct it is convenient to use when at you the code in style of a C - i.e. there are no methods/designers.

Or when trejty/metafunctions you write

7

Re: Difference Class from Struct

rdb_dev wrote:

Anatoly Moskovsky, there is one more small difference - presence/absence by default the pointer on VTBL.

If the virtual methods are not present - any VTBL does not form

8

Re: Difference Class from Struct

rdb_dev wrote:

there is one more small difference - presence/absence by default the pointer on VTBL.

There is no such.

9

Re: Difference Class from Struct

Anatoly Moskovsky, yes... It seems that I forgot about real assignment and usage reasons __ declspec (novtable) .
I repent, it was wrong!

10

Re: Difference Class from Struct

Anatoly Moskovsky wrote:

struct it is convenient to use when at you the code in style of a C - i.e. there are no methods/designers.

or on the contrary, when there is no the data, and all methods - public and, probably, abstract

11

Re: Difference Class from Struct

Anatoly Moskovsky wrote:

semen.s.semen;
There is no difference besides that in struct all members by default public, and in class - by default private.

There is one more difference - inheritance from ancestors in struct by default public , in class by default private .
I.e. in struct it is possible not to write

class ParentCl;
//...
struct ChildStruct:/* public */ParentCl//public here it is possible to lower.
{
//...
};

12

Re: Difference Class from Struct

rdb_dev wrote:

Anatoly Moskovsky, there is one more small difference - presence/absence by default the pointer on VTBL.

No, such difference is not present. The pointer on vtbl in any class or structure appears only with appearance at least one
The virtual method in hierarchy. Such classes/structures pointerful on vtbl are called as polymorphic classes;
And without it - not polymorphic. And they differ from each other in particular also application possibility to them RTTI and
dynamic_cast.

13

Re: Difference Class from Struct

MasterZiv, I was confused by storage of presence __ declspec (novtable). Forgot that is normal this directive apply to purely abstract classes.

14

Re: Difference Class from Struct

rdb_dev wrote:

MasterZiv, I was confused by storage of presence __ declspec (novtable). Forgot that is normal this directive apply to purely abstract classes.

At first, it not the standard, and the extension any, secondly, as to the abstract class and without vtable?
P.S. Esteemed about it - generally  any... But also then - it does not delete vtable, it deletes only usage of it vtable (pointer initialization) from the designer and .

15

Re: Difference Class from Struct

Anatoly Moskovsky wrote:

semen.s.semen;
There is no difference besides that in struct all members by default public, and in class - by default private.

It is possible unless to add. Still is union, at it too on silence public as well as at struct. And too can be both methods, and virtual etc.

16

Re: Difference Class from Struct

MasterZiv wrote:

At first, it not the standard, and the extension any, secondly, as to the abstract class and without vtable?
P.S. Esteemed about it - generally  any... But also then - it does not delete vtable, it deletes only usage of it vtable (pointer initialization) from the designer and .

So  to the abstract class to have the virtual method table if it never , and is used only for the interface and inheritance description? To the compiler the nobility only the order declarations of the virtual methods of this class, and vtable suffices it without need.

17

Re: Difference Class from Struct

rdb_dev wrote:

to the Compiler the nobility only the order declarations of the virtual methods of this class, and vtable suffices it without need.

As far as I know, nobody forbids to have method implementation in the abstract class.
And, as far as I understand, at least,  the abstract class will be virtual.
P.S.
Extreme  - a disturbing call.

18

Re: Difference Class from Struct

Basil A. Sidorov wrote:

As far as I know, nobody forbids to have method implementation in the abstract class.
And, as far as I understand, at least,  the abstract class will be virtual.

to Have implementation of virtual , certainly it is possible - nobody forbids... But if a class is exceptional interface  it is necessary? We assume, at you a floor of hundred the virtual methods (I, of course, am kidding) and layout vtable on models ILP64/LP64/LLP64 adds to the binary unit almost a kilobyte floor. And if such interface classes not one and not two?
At me in one small project was seven interface classes, in each of which of the order 15 - purely virtual 20 methods.

Basil A. Sidorov wrote:

P.S.
Extreme  - a disturbing call.

it is quite possible... At GCC, by the way, I similar did not note anything (can is bad looked).

19

Re: Difference Class from Struct

rdb_dev wrote:

we Assume, at you a floor of hundred the virtual methods (I, of course, am kidding) and layout vtable on models ILP64/LP64/LLP64 adds to the binary unit almost a kilobyte floor.

the Physical minimum of unit of storage on a disk - those "halves a kilogram" about which you so are baked.
Simple creation of record about a file in the directory "eats off" tens-hundreds byte.
To what all this hairsplitting???
Perhaps to waste time with favor and to refine design of the project or to reduce release periods?.

20

Re: Difference Class from Struct

Basil A. Sidorov wrote:

the Physical minimum of unit of storage on a disk - those "halves a kilogram" about which you so are baked.
Simple creation of record about a file in the directory "eats off" tens-hundreds byte.

If in a crude format yes, but set of file systems use a cluster on 4, 8, and even 16  and if  hardly got out for cluster limits though on byte under it all cluster entirely leaves.

Basil A. Sidorov wrote:

To what all this hairsplitting???

I do not know... It is necessary  to ask. smile

21

Re: Difference Class from Struct

Basil A. Sidorov wrote:

To what all this hairsplitting???

To whom and a cancer fish, and at someone and pearls small)))
/ free retelling of popular wisdom, I word-for-word do not remember / it

MSDN wrote:

Using this form of __ declspec can result in a significant reduction in code size.

22

Re: Difference Class from Struct

rdb_dev wrote:

it is passed...
So  to the abstract class to have the virtual method table if it never , and is used only for the interface and inheritance description? To the compiler the nobility only the order declarations of the virtual methods of this class, and vtable suffices it without need.

And pure virtual function call who will speak?

23

Re: Difference Class from Struct

MasterZiv wrote:

And pure virtual function call who will speak?

Pure virtual functions in pure abstract class? smile

24

Re: Difference Class from Struct

I so understand that at M $ the declaration of classes it is frequent __ interfaces. Neither to be inherited, nor to create instance from them plans nobody. For example declarations of classes under interfaces COM of objects.
AFAIK

25

Re: Difference Class from Struct

Leonid Kudryavtsev, OOP and the virtual methods of objects have no relation to COM and OLE. COM and OLE are quite really written purely by a procedural language without any troubles. It simply specification of the interface of the interaction, superficially resembling OOP.