Structures and classes

What's the difference between structures and classes? Is there a certain I should use a class and not a structure and vice versa? The only difference between a structure and a class I know is that classes can have private, public, and protected (I think) vars/functionss.

Best Regards,
CodeKing

Comments

  • [b][red]This message was edited by MT2002 at 2007-3-20 16:0:22[/red][/b][hr]

    : What's the difference between structures and classes? Is there a certain I should use a class and not a structure and vice versa? The only difference between a structure and a class I know is that classes can have private, public, and protected (I think) vars/functionss.
    :
    : Best Regards,
    : CodeKing
    :
    [blue]
    In C++, the only difference is that structure members are public by
    default, while classes are private.

    Both classes and structs could include private,public,and
    protected members.

    Also, classes support inheritance, structs dont. (I might be
    incorrect here--Please correct me if Im wrong)

    C++ only supports structs for backward compatibility. If you
    are using C++, it is better to use classes then structs because
    of encapsulation and inheritance--two fundemental princibles
    behind OOP and OOD, in which C++ was built on.

    Hope this helps :-)[/blue]
    [/blue]
  • : In C++, the only difference is that structure members are public by
    : default, while classes are private.
    Correct, and that is the only difference.

    : Also, classes support inheritance, structs dont. (I might be
    : incorrect here--Please correct me if Im wrong)
    This is incorrect :-) (or at least compiler dependent: under Borland C++ Builder this is possible for sure).

    See ya,
    bilderbikkel

  • : : What's the difference between structures and classes?
    : [blue]
    : In C++, the only difference is that structure members are public by
    : default, while classes are private.
    :
    : Both classes and structs could include private,public,and
    : protected members.
    :
    : Also, classes support inheritance, structs dont. (I might be
    : incorrect here--Please correct me if Im wrong)
    :
    : C++ only supports structs for backward compatibility. If you
    : are using C++, it is better to use classes then structs because
    : of encapsulation and inheritance--two fundemental princibles
    : behind OOP and OOD, in which C++ was built on.
    :
    : Hope this helps :-)[/blue]
    : [/blue]
    :
    Classes are in fact derived from structures, but they additionally contain functions to work on their data. These are called methods in C++. (In Object Pascal, structs and classes are even closer.)
    Greetings, FDrache.


  • : : : What's the difference between structures and classes?
    : : [blue]
    : : In C++, the only difference is that structure members are public by
    : : default, while classes are private.
    : :
    : : Both classes and structs could include private,public,and
    : : protected members.
    : :
    : : Also, classes support inheritance, structs dont. (I might be
    : : incorrect here--Please correct me if Im wrong)
    : :
    : : C++ only supports structs for backward compatibility. If you
    : : are using C++, it is better to use classes then structs because
    : : of encapsulation and inheritance--two fundemental princibles
    : : behind OOP and OOD, in which C++ was built on.
    : :
    : : Hope this helps :-)[/blue]
    : : [/blue]
    : :
    : Classes are in fact derived from structures, but they additionally contain functions to work on their data. These are called methods in C++. (In Object Pascal, structs and classes are even closer.)
    : Greetings, FDrache.
    :
    :
    :

    Generally, unless I am coding purely in C I always declare what access I want any, eg. I always put either protected:, private: or public: before a lump of code, not between every line as required in Java. Henceforth, I find that in practice they're really identical, for me. I simply stick with using the class keyword always unless using c purely.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories