A few questions

1) What does it mean when you declare a class as the following :
 
class Name : public Something 


2) I've seen before an instance of a class being set to something, for example :
 
Name Bob = get_name();


Did I read it wrong? Or is this possible somehow? If so, what does it accomplish?

3) What does an iterator do?


Thank you everyone for your help :)
1) That declares Name to be a derived class of Something, with it's members inherited as public.

2) I'd need to see more code to be sure, but that looks kind of like a singleton.

3) Basically, they let you refer to ranges. The point is to let you go from one end to the other of a range ('iterate' over the range) without having to know the details of the container/array/range itself.
1) class Name : public Something
This is called inheritance. The class Name inherits the contents of the class Something, so if the class Something was declared like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Something
{
    public:
        int publicVar;
        void publicFunc();

    protected:
        int protVar;
        void protFunc();

    private:
        int privVar;
        void privFunc();
};

then the class Name would inherit variables and functions(methods) declared under public: and protected: fields.
It would not inherit privVar and privFunc() because they're under private: field, so they are private to the class Something only.

So an object of type Name would hold all the variables and methods of class Name plus the publicVar, protVar, publicFunc() and protFunc(), which are inherited from class Something.

2) Name Bob = get_name();
This means you've got yourself a function get_name() which returns an object of type Name which is then copied to the contents of the object Bob. What this code does is: it creates an object of type Name called Bob using the default constructor, then executes the function get_name() which returns an object of type Name. The contents of this object are assigned to the contents of Bob.

3) No freaking idea, I can imagine what it may be because I know what an iteration is but I better leave the answer to someone else. By the way, google and wikipedia are your friends. They should be the first thing you use when you have questions. Here's the topic about iterator in wikipedia: http://en.wikipedia.org/wiki/Iterator
Last edited on
Ah thanks to the both of you, I get it now :) great help thanks guys :D
Topic archived. No new replies allowed.