help with some C++ topics?

Hi, I've been going at C++ for a couple months now, and only understood it for about half of the months. I'm pretty good on most things, like arrays, string functions, structs, the looping/logic statements(if, else if, etc.) But I am very cloudy on some other things, and why they are even helpful! I have looked at a lot of code examples, tutorials, all of it. But I just can't seem to understand the following:
classes, pointers, vectors, inheritance, headers/use of headers, and especially polymorphism.

I don't need fully worded tutorials on each thing listed above, I just want to know what they are, why they're helpful, and maybe a small code example. Any help is appreciated. Thankyou!
Last edited on
classes, pointers, inheritance and polymorphism are explained in the link moorecm posted. Vectors: http://www.cplusplus.com/reference/stl/vector/ . Headers: http://www.cplusplus.com/forum/articles/10627/
My apologies, I didn't clarify... I am not looking for links, I have already looked at all of those tutorials :-/

I'm looking for actual replies in the thread, about the topics I listed above. If you have a way of explaining those topics to an A.D.D.-10 year old (I'm not 10), then that's the way for me. Sorry for not clarifying above.
there is no point of understanding what classes are and what vector is etc.
cos understanding of for example classes and not learn how to use or code a class is just useless.

best way is to PRACTICE CLASSES by coding and understand them by the way :D
Well that's what I want to do!! but I can't do it if I've no idea what the use of a class is, compared to something like a struct (which I know how to use,) if you could just explain to me what a class is, then I could practice.
I'm not sure what we can tell you that a tutorial didn't..
closed account (z05DSL3A)
+1 hamsterman.

A class is an object. Think of it like a little mini computer. It can do things, and it can store things.
closed account (z05DSL3A)
ultifinitus wrote:
A class is an object

A class is more like the blueprint from which individual object are created.
Whoops, yep sorry =) Shoulda said class instance.
I'm not sure what we can tell you that a tutorial didn't..


This. The information is there you just have to read it. That should be no big deal since you'd have to read our replies too... At this point, the excuses are starting to sound like laziness.
@doesoxena
sorry if I'm wrong but I think u miss a book.
I think you should buy a good book.

it's very hard to learn C++ or any other language just on the internet or reading forums.
buy a book, learn chapter by chapter, then when u don't understand something come here and ask people on how to do that. ( if answer is not clear enough in your book)

by the way book is not so expensive and you will not regreat the money.

EDIT:
don't download a book form internet and read on your computer cos u will burn your eyes over time :D
Last edited on
But I just can't seem to understand the following:
classes, pointers, vectors, inheritance, headers/use of headers, and especially polymorphism.

@desoxena: This sounds like a classic case of not having programmed enough.

There's only so much you absorb by reading tutorials and listening to someone explain a concept. You have to implement the features into your own programs, to really get a feel for what they are.

When I didn't understand a concept, I would complete as many exercises as I could on the particular subject matter until it finally sunk in.

Good luck, and if you have any specific programming questions feel free to ask them here, I'm sure someone will help you out! :D
Here's a little example on classes, hopefully it helps...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//This creates our "CuteKitty" class..
Class CuteKitty
{
//Remember using classes that EVERYTHING is by DEFAULT private
//you have to actually set it as public to access it
public:
     CuteKitty(int Height, int Weight);
     ~CuteKitty() {}
     void SetHeight(int Height) { itsHeight = Height; }
     int GetHeight() const { return (itsHeight); }
     void SetWeight(int Weight) { itsWeight = Weight; }
     int GetWeight() const { return (itsWeight); }
//Private functions can ONLY be accessed by the class itself so in
//other words you need to use SetHeight/SetWeight to change these
private:
     int itsHeight;
     int itsWeight;
};

//This is our constructor, as soon as an object of the class is created
//this is called
CuteKitty::CuteKitty(int Height, int Weight)
{
     itsHeight = Height;
     itsWeight = Weight;
}


NOTE: I added "const" after GetHeight and GetWeight. The reason for this is because it does not change anything in the class, but constantly returns itsHeight or itsWeight. This is good programming for a few reasons, but the main reason is that it is easier to debug if you're having any problems.

Now to create an object of the class...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
using namespace std;

int main()
{
       //Creates an object of CuteKitty called MyCat with a height of 2
       //and weight of 40 using constructor
       CuteKitty MyCat(2, 40);

       //Uses our classes GetHeight, GetWeight functions to retun private values
       cout << "Cats height: " <<  MyCat.GetHeight() << endl;
       cout << "Cats weight: " << MyCat.GetWeight() << endl << endl;

       int Height, Weight;

       //Uses our classes SetWeight function to set private values
       cout << "Enter cats new weight: ";
       cin >> Weight;
       MyCat.SetWeight(Weight);

       //Uses our classes SetHeight function to set private values
       cout << "Enter cats new height: ";
       cin >> Height;
       MyCat.SetHeight(Height);

       cout << "Cats new height: " <<  MyCat.GetHeight() << endl;
       cout << "Cats new weight: " << MyCat.GetWeight() << endl << endl;

   return 0;
   //End of main scope so the class destructor is called
}
don't download a book form internet and read on your computer cos u will burn your eyes over time :D

You won't? There is no difference from reading a book on a monitor that doing anything else on it, but of course, it's easier to consentrate if you read from a physical book. I'm kind of starting to like those eBooks though (iPad) :)
Thankyou TheNoobie! Now I know how to use classes, thankyou so much :D

however, in response to the above comments, I did read the tutorial, extensively, and thoroughly. But it just didn't make much sense to me. The tutorials seem to be aimed at people who might know almost all of the material already, and merely need a brush up.
desoxena wrote:
The tutorials seem to be aimed at people who might know almost all of the material already, and merely need a brush up.

This isn't true. The tutorials (in this site and generally) cover the different aspects of the language quite well; The example @TheNoobie gave (or something similar) is available in many tutorials. Sometimes understanding the tutorials requires compiling every piece of code and trying it out, especially if you have no previous programming experience. You should also look at more than one tutorial/resource if you don't understand something the first time. Mastering those topics might take more time than you have anticipated but you should really try as hard as you can.

I wish you good luck :)
closed account (3TXyhbRD)
Can you give me some chapter names of what you have studied so far in C++?
Topic archived. No new replies allowed.