Dereferencing Class Pointer List

This is a discussion on Dereferencing Class Pointer List within the C++ Programming forums, part of the General Programming Boards category; I have provided the definitions, although I don't think the constructors or Add() functions are the problem. I runs fine ...

I have provided the definitions, although I don't think the constructors or Add() functions are the problem. I runs fine in Release Mode, however when i try to access a container through the pointer list class, it gives an error.... Pointers are confusing..

Your compiler is hopefully also throwing numerous warnings about how you are passing const char pointers into your constructors/functions and assigning them to non-const char pointers. This is very dangerous. You might be tempted to try modifying those internal strings at some point, at which time you will most likely experience crashes.

I understand that you're trying to learn about pointers, but your usage of them is pretty ridiculous at times, and in several places you would be better off not using pointers. I find this code very hard to follow.

Crap! Did not know why I was doing that! That was an error generated right after fixing the errors I previously asked. It all works now! Although when I compile it in DEBUG mode it still forces that break point. It only works if I compile it in release mode. Can anyone explain why the error happens in debug mode?

And BTW, I was adding to this code around 3:45 AM, so that could probably explain that stupid stunt...

[edit]
By the way, which compiler are you using? I just compiled the exact code you posted, plus the fixes I suggested, using both the MinGW compiler and Visual Studio 2008, and neither of them gave me any compilation/runtime errors.
[/edit]

Well that's odd. I originally began to code this with Code::blocks, and then I migrated to Visual Studio 2005 w/out any service packs installed ( might be the reason? ). I tried to recompile the code once again in Code::blocks after the progress done with Visual Studio 2005 and compiles it flawlessly. Perhaps it is one of the Preprocessor flags included in the DEBUG mode, and I believe it is _HAS_ITERATOR_DEBUGGING.

>> Pointers are confusing..
Yep, and you're having a hard time with them. You're also using them in many places where it is not necessary, and now you have a program full of pointer errors. Unfortunately you've got a lot more to fix up besides the mismatched iterators.

The first thing I see is that you don't have a copy constructor or copy assignment operator for your SingleListClass even though you have a member variable allocated with dynamic memory. The rule of three says that if you need a destructor, copy assignment operator or copy constructor, you probably need all three. Here you have a destructor and you need the other two. A better solution is to not use a pointer here. There's no benefit and if you don't use dynamic memory you won't need the destructor, copy assignment operator or copy constructor.

The second thing is that you leak memory in SingleListClass::Add(). You allocate a temp _medContainer dynamically, then you push_back a copy of the object. You never delete the temp one (the copy will be cleaned up automatically by the list).

There's probably a lot more errors lying around, I haven't looked closely. I'd suggest using pointers only where they're necessary and learning how to use them correctly that way first.

As to your original problem, did you try the main() program example I posted? Did it work or fail? In Release mode it might work because the extra checks done by the compiler to help you are skipped, you want to make sure it works in debug mode and release mode.