PDA

View Full Version : STL_Containers exercise



anon10320
09-04-2013, 10:18 AM
Sir,
In the stl containers exercise,Q.-2 (easy) it is said that introduce errors in the STL constructor and debug them .My question is that if there will be any error in the program then how one could use gdb to debug .

Thanks
anon10320

anup
09-04-2013, 10:20 AM
Anon10320,

You have a valid point regarding the use of word *debug*. What is meant is to introduce compilation errors and fix those. We will reword it in a later version of the course.

Thanks,

Anup

anon10320
09-04-2013, 10:33 AM
Sir,
What is the advantage to use const_iterator in place of iterator ? I've used const_iterator in my code and it is working same like as earlier.

Thanks
anon10320

anup
09-04-2013, 10:47 AM
Anon10320,

const_iterator returns you constants, you cannot modify the values.

Thanks,

Anup

anon10320
09-04-2013, 03:27 PM
Sir,
In my code when ,I use const_iterator it gives same output as iterator.Sir, give me any example in which the output could be differ in both the cases -Iterator and const_iterator.

Thanks
anon10320

basant
10-04-2013, 08:15 AM
Anon10320,

Suppose you have a vector as follows.
vector<MyClass*> vec;

If you use const_iterator, then you would get object of type 'const MyClass *', but if you use iterator, then your object will be of type 'MyClass*'. The difference between these two is that you cannot change the value inside the first one. On the other hand, the second one can change.

I would suggest that you should try to modify field of the object and see what compiler says in both the case.

-- Basant