If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Vector, class, and iterator issues

Originally Posted by Escapetomsfate

Oh Yeah.....

So how do I set it up?

Below are links to a short movie (recorded on a test VM; quality should be acceptable) that illustrates one of the methods that I was talking about.
You may also need VMware's Movie Decoder if you don't have one of their products installed.

Re: Vector, class, and iterator issues

Originally Posted by Plasmator

Below are links to a short movie (recorded on a test VM; quality should be acceptable) that illustrates one of the methods that I was talking about.
You may also need VMware's Movie Decoder if you don't have one of their products installed.

Does anyone know wha that could mean, in relation to the code at the start?

You are accessing an address via pointer for reading, and that address you're attempting to access is NULL (0x00000000).

Set a breakpoint on the very first line of your application, and keep your eye on the Output Window. If that message hasn't appeared when the first line is about to execute, single step through the program until that message appears. When that message appears, then that area of code is where it's triggering that message.

Usually reading from a NULL address isn't fatal, but irritating seeing that message. The fatal one is when you attempt to write to a NULL address.

If that message appears before the first line in your main() program, then either you have global classes, objects, that were instantiated, and that is the cause of the problem, or if you're using other DLL's that get loaded at app startup, then they could be the ones causing the problem. You need to just debug slowly to pinpoint where that message is being generated from.

BTW, since you are using Visual C++, you should have posted this in either the Visual C++ forum (if using MFC) or the Windows API forum (if you're using straight Windows API calls).

Re: Vector, class, and iterator issues

Originally Posted by Paul McKenzie

You are accessing an address via pointer for reading, and that address you're attempting to access is NULL (0x00000000).

Set a breakpoint on the very first line of your application, and keep your eye on the Output Window. If that message hasn't appeared when the first line is about to execute, single step through the program until that message appears. When that message appears, then that area of code is where it's triggering that message.

Usually reading from a NULL address isn't fatal, but irritating seeing that message. The fatal one is when you attempt to write to a NULL address.

If that message appears before the first line in your main() program, then either you have global classes, objects, that were instantiated, and that is the cause of the problem, or if you're using other DLL's that get loaded at app startup, then they could be the ones causing the problem. You need to just debug slowly to pinpoint where that message is being generated from.

BTW, since you are using Visual C++, you should have posted this in either the Visual C++ forum (if using MFC) or the Windows API forum (if you're using straight Windows API calls).

Regards,

Paul McKenzie

Thanks for the help. I already know that this is the code causing the CTD:

Re: Vector, class, and iterator issues

Thanks for the help. I already know that this is the code causing the CTD:

There are several lines posted there. Which one is it that is causing the problem?

As others pointed out, we need to see the full context of when, where, and how that code is called, we do not know what the values of any of those variables are when that code is called, etc.

Since this is a runtime issue, we can't do static analysis of source code to show you what you're doing wrong. All we can say is that the loop syntactically is correct. If WeaponList is valid, and if explode() has no issues, then that code is correct (Note the if -- only you know whether any of those things are valid or not).

Re: Vector, class, and iterator issues

Originally Posted by Escapetomsfate

EDIT: Could this be it? it is in the Weapon class constructor.

Code:

//add self to WeaponList vector.
WeaponList.push_back(*this);

You're adding a copy of a not yet constructed object to a vector. Could very well be a problem especially since you seem to have no copy constructor defined for the Weapon class that has some pointer members.
Kurt

Re: Vector, class, and iterator issues

Originally Posted by Escapetomsfate

I only get an error when I use a function of the iterator (it, using Weapon class functions).

Then that loop would never execute if the WeaponList is empty. Look at the for loop constraints. Second, if that loop did execute, that means that the WeaponList is not empty, and one of the item's in that list has an explode() function that is buggy, or the item itself is buggy.

How do I make a class push back itself on construction?

I don't understand your question. How would that fix the issue I stated above?

I'm sure that's the problem.

Hopefully you are not guessing at what the problem is. You never should guess, you have to actually debug, find the cause of the problem, and then offer a diagnosis to fix the problem.

Re: Vector, class, and iterator issues

Originally Posted by ZuK

You're adding a copy of a not yet constructed object to a vector. Could very well be a problem especially since you seem to have no copy constructor defined for the Weapon class that has some pointer members.
Kurt