Hey, i've been studying c++ for a while now. I've recently been learning about the class datatype. What exactly would you use a class to do? Thanks for taking time. have a good day.
Hey, i've been studying c++ for a while now. I've recently been learning about the class datatype. What exactly would you use a class to do? Thanks for taking time. have a good day.
a class let you have data that protected, private, and public
which can help safeguard stuff. a class also lets you have a
bunch of function inside it that you can get to thru the class.
i dont know if that awnser your question, here a example
of what a class looks like :
I jsut typed that out real fast i might of made a typo but thatCode:#include <iostream> using namespace std; class math { public: int add(int a, int b) { return (a+b); } }; int main() { math plus; //Let you use the word plus to talk to the functions in the class //To use a function inside the class you would cout << plus.add(1, 3) << endl; //Another way to use the function int value = plus.add(1, 3); cout << value << endl; cin.get(); return 0; }
the general construct, so people will put there function
else where and just have the declartion of it inside the class.
A Class Tutorial
Last edited by ILoveVectors; 06-26-2005 at 08:27 PM.
Hey, thanks for the info. That gives me a better understanding of a class. Knowing when to use the constructors and destructors is still confusing, but all is well.. just got to look at the tutorials.
Thanks.
--Alex
A contructor, you can place statment in to collect data or display
data when a class is created.
For a destructor you can place data in it to state when the class
is done and you destroy it. A destructor can also contain code
to do any memory managment you need. such as freeing memory.
Last edited by ILoveVectors; 06-26-2005 at 08:25 PM.
very important. 1st learn to use structures. later you can think in classes
I think classes are easier consept to learn first, then you can apply the concepts to structures. I learned classes first, and they come before structures in the curriculum i took.Originally Posted by xErath
interesting since i always that struct were just class
without functions and less data protection,
id think struct would be easier to learn.
then agian some of the things you can use struct for are
actually prolyl more difficult then the concept of a class,
so that prolly why you learned them after classes.
In C++, the only difference between a struct and a class is the default access specifier.
class defaults to private, whereas struct defaults to public.
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers
Structs and classes are the same thing in C++. Structs just default to public where as classes are default to private.
Woop?