-1

For example, what is the difference between:

strucut Nodo{
    Nodo *siguiente,*anterior;
    char* Nombre,Curso;
    long,carnet;
    Nodo(){
        siguiente=anterior=NULL;
    }

and:

class Nodo{
public:    
Nodo *siguiente,*anterior;
char* Nombre,Curso;
long carnet;
Nodo(){
    siguiente=anterior=NULL;
    }

A difference that i think i saw was that in class you must put public, or in other hand all the statements will be private, but i can“t see any important difference, or any crusial difference. There are some important aspect that i dont know?

1 Answers1

7

The only difference between a class and a struct is the default access specifier. A class's members are private by default, whereas a struct's members are public by default. This also means that class inheritance is private by default and struct inheritance is public by default.

As described by the standard:

Members of a class defined with the keyword class are private by default. Members of a class defined with the keywords struct or union are public by default.

And for inheritance:

In the absence of an access-specifier for a base class, public is assumed when the derived class is defined with the class-key struct and private is assumed when the class is defined with the class-key class.

Joseph Mansfield
  • 108,238
  • 20
  • 242
  • 324