C ++ - structure versus class

Possible duplicates:
C / C ++ Struct vs Class
What are POD types in C ++?

Hello,

In C ++ In a nutshell , in chapter 6: classes , below Access Specifiers , the following is mentioned:

In the default class definition, access for members and base classes is private. In the structure definition, default is public. This is the only difference between a class and a struct , although by convention some programmers use struct only for POD classes and use the class for all other classes .

My questions are here:

  • Is there no other difference between classes and structures in these structures that do not contain functions and simply store data?
  • What are POD classes? And what is meant by all other classes here? Are there special classes?

Thank.

+43
c ++ struct class pod
Jan 25 '11 at 9:40
source share
5 answers

Another difference is that

template<class T> ... 

allowed but

 template<struct T> ... 

no.

+89
Jan 25 2018-11-11T00:
source share

You could prove to yourself that there is no other difference when trying to define a function in a structure. I remember that even my college professor, who taught about structures and classes in C ++, was surprised to learn about it (after correction by a student). I believe that. That was fun. The professor continued to say what the differences were, and the student continued to say: "In fact, you can do this in structure too." Finally, prof. asked “OK, what is the difference”, and the student informed him that the only difference was the default availability for participants.

A quick Google search suggests that POD stands for "Plain Old Data."

+37
Jan 25 2018-11-11T00: 00Z
source share

POD classes are Plain-Old data classes that only have data and nothing else. There are several questions about stackoverflow about the same. Find it here .

In addition, you can have functions as members of structures in C ++, but not in C. You need to have pointers to functions as members in structures in C.

+8
Jan 25 2018-11-11T00:
source share

Well, POD means plain old data. This usually means structs without any methods, because these types are then used to structure multiple data that belong to each other.

As for structures that do not have methods: I have already seen more than once that a structure has methods, and I do not feel that this would be unnatural.

+3
Jan 25 2018-11-11T00:
source share

1) This is the only difference in C ++.

2) POD: plain old data Other classes -> not POD

+2
Jan 25 2018-11-11T00:
source share



All Articles