Mail Archives: djgpp/1999/03/11/09:57:24
Bjørn Hansen wrote:
> This is really a general C++ question but I don't read any other
> newsgoup So. . .
>
> Anyway is there any reason to use a structure instead of a class in C++?
If you're doing c++, and especially if you're like me and change from c to
c++ depending upon which day it is, you have to adjust your thinking from
"c-mode" to "c++-mode."
In c, a structure is a structure, you know it, you love it--it's familiar.
In c++, what we call a structure is REALLY a class whose members are public
be default. It's a subtle change, true, but an important one. For example,
the scope resolution operator, member functions all are valid things to do
with structures in c++. I minimize confusion on my part (since I'm usually
the guy who has to fix things), by only using structures when I want them to
be EXACTLY the same as c structures--no member functions, only public data,
and use classes for everything else.
That works for me, buy YMMV.
Charles
- Raw text -