C
Carfield Yim
I've tried in gcc, it is allowed to have methods in a struct, so this
is same as a class, is it?
is same as a class, is it?
See <http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7.8>I've tried in gcc, it is allowed to have methods in a struct, so this
is same as a class, is it?
Carfield Yim said:I've tried in gcc, it is allowed to have methods in a struct, so this
is same as a class, is it?
I've tried in gcc, it is allowed to have methods in a struct, so this
is same as a class, is it?
Carfield Yim wrote, On 21.3.2009 11:48:> I've tried in gcc, it is allowed to have methods in a struct, so this
See <http://www.parashift.com/c++-faq-lite/classes-and-objects.html#faq-7..8>
C++ is backwards compatible with C struct declarations. I think
backward compatibility is the biggest reason for retaining structs.
The only difference i am aware of is that structure members have
public access by default and class members have private access by
default
The FAQ alludes to another difference but it's more a cultural
difference than a legal one. According to the FAQ, most programmers
use the word struct for a particularly simple class -- for example one
which doesn't inherit and which won't form a base of any inheritance
hierarchy.
That was the convention of my previous company -- the keyword struct
was used for a simple class.
Paul Epstein
Andrey said:Usually struct is using as a type that have a state but doesn't have
behavior. I means that there are public fields and there is no
methods.
Suraj said:C++ is backwards compatible with C struct declarations. I think
backward compatibility is the biggest reason for retaining structs.
The only difference i am aware of is that structure members have
public access by default and class members have private access by
default
On Mar 21, 9:23 pm, (e-mail address removed) wrote:
Usually struct is using as a type that have a state but
doesn't have behavior. I means that there are public
fields and there is no methods. This type usually is using
as a parameter of a method and/or aggregate object. It is
not a restriction but is some convention can be adopted by
developers (of the company for instance).
Ian said:Don't forget the same applies to default inheritance.
In other words a C style struct.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.