I'm just starting to program and I'm trying to figure out what the difference in a struct and a class is? I've tried google, but I'm still confused. Could someone give me a hand?
I'm just starting to program and I'm trying to figure out what the difference in a struct and a class is? I've tried google, but I'm still confused. Could someone give me a hand?
Struct makes more sense.
A struct holds data only
classes hold data AND functions
By default a structures members are public and a class's members are private. Class's support the concept of inheritance, yada, yada, yada.
Take a look at this tutorial
Last edited by andyhunter; 02-11-2005 at 10:43 PM.
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
Thanks for the responses....I supposed I shouldn't even bother to ask about what you mean by ineritance yet...
As far as you are concerned, there is no difference. There is one tiny difference, but don't worry about it now. In C++, you use classes.
Ok cool.
So with classes then I put all my variables in one place instead of at the top of my program?....
Did you read the tutorial? That is a very vague question.
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
Nevermind, I'm dumb. I just found the answer in the tutorial. \
Thanks andyhunter!
You aren't making sense, but that's part of being a beginner. Maybe provide an example of what you mean.So with classes then I put all my variables in one place instead of at the top of my program?....
Last edited by 7stud; 02-11-2005 at 10:57 PM.
No I have it all figured out now i think....I was confusing how classes worked with global variables. If I use classes then I don't have to have global variables right?
thanks for all of the help!!!!!!
...so do structs. There is no yada, yada, yada.Originally Posted by andyhunter
Code:#include<iostream> using namespace std; struct A { int x; }; struct B: public A { int y; }; int main() { B b; b.x = 10; b.y = 20; cout<<b.x<<endl<<b.y<<endl; return 0; }
Whoa, whoa, whoa. Look at that, and here I though the whole inheritance thing was brought about with C++. So the new C std does allow for inheritance.
i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced
It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah
Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem
I would hazard to guess that you shouldn't be using global variables at all as a beginner. Classes are much different than variables of type int, float, string, etc.If I use classes then I don't have to have global variables right?
I posted a simple example of inheritance above. Basically, if one class inherits another class, it has all it's variables and functions.
I doubt it. Structs in C++ are classes with public access by default, i.e. they do everything classes do including member functions, constructors and inheritance. In C, they hold only variables/other structs.So the new C std does allow for inheritance.
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.