joshdick, they can do everytihng that classes can do
joshdick, they can do everytihng that classes can do
Really? I've never seen structs with constructors or functions. Could you please show me an example of functions in a struct coded out for me? Thanks in advance.Originally posted by Polymorphic OOP
joshdick, they can do everytihng that classes can do
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
Code:struct HelloWorld { private: int hello, world; public: HelloWorld() : hello(0), world(1) {} HelloWorld(int x, int y) : hello(x), world(y) {} void PrintHello(void) { cout << hello << endl; } void PrintWorld(void) { cout << world << endl; } };
Wow. I've never seen that. I've always seen structs used in a much simpler way than classes. Hmm. So why use one over the other? I know that structs default to public and classes to private, but besides that, what's the difference between the two?
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
structs also default to public inheritance while classes default to private inheritance.
other than those differences, nothing.
There is no other difference. Structures were included for compatibility with C code.
Huh. Thanks for enlightening me, guys. So, does that mean that I could create a class that just had public data members without any functions or constructors/destructors?
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
Huh, this is really quite a revelation to me.
Um, so, if there's very little difference between structs and classes, why were classes introduced to C++? Why couldn't C++ just continue using structs?
FAQ
"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.
"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.
because C++ classes are very different from C structs. C structs aren't capable of member functions, etc.
Why they introduced the name "class?" It certainly wasn't a necissary addition -- probably just to further emphasize the differences between C++ classes and C structs. The reason "structs" still exist is for compatability.
C structs and C++ structs are diff from each other.
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
i was thinking of this
Who says that this is a school project or that I am even in school still? I think that was a bad assumption Pode.
i meant you should go to your teacher (or your mom) and ask them to teach you to write.I am not talking about making a computer game here...more of an application for the pen and paper type of game. Any other ideas?
Originally posted by pode
i meant you should go to your teacher (or your mom) and ask them to teach you to write.
You are really out of it....I am not in school anymore (been a LONG TIME) and I am old enough that I don't need my Mom (not like she knows how to program or even turn on a computer).
All I was asking was some simple ideas if anyone in these forums has done anything similar. I can think of some ideas on how to do it but stuff like printing out of the character sheet with the stats they want on it stumps me right now as I have not done much programming with printing out to a printer (graphics, bitmaps, etc.)
u was asking for help with pen and paper
so i thought maybe u could'nt write(with pen)
so i told u to ask your teacher(that's what they're for)
or your mom(if she got the time)
I usually use the different keywords just for mental note. I use structs for anything that is just storing variables and classes for anything else. But you could just use all structs or all classes.