I know this is a silly question, but is this code okay? It compiles on my compiler (not, of course, that that means anything):
(I know that structs are public by default etc.)Code:class aclass {}; int main(void) { struct aclass a; }
I know this is a silly question, but is this code okay? It compiles on my compiler (not, of course, that that means anything):
(I know that structs are public by default etc.)Code:class aclass {}; int main(void) { struct aclass a; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
class and structs are the same thing, though in your example prefixing struct to your class instance wouldn't make its member public ( if it had any)
I don't think structs have inheritance.
- SirCrono6
From C to shining C++!
Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
- Bubba
IDE and Compiler - Code::Blocks with MinGW
Operating System - Windows XP Professional x64 Edition
Nope. That is incorrect.Originally Posted by SirCrono6
Structs and classes will produce the exact same assembly code.
The 2 important differences are
- structs are public by default
- forward declarations must match (i.e. a forward declared class cannot be defined as a struct or vice versa)
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Okay, thanks, I guess I didn't know point 2.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
You probably want to use classes, they were designed for C++ whereas structs were left over from C. Good luck!
EDIT: I didnt mean to imply they were different, but i believe the standard is Classes
Last edited by Junior89; 11-25-2005 at 04:39 PM.
Actually, as mentioned, they're almost exactly the same thing. Read the thread.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.