When I debug, I can't get past the last line here, and I get the message: "No source code available for this location." Then it allows me to look at the assembly, which I don't understand but will be happy to copy here if you guys need it to figure out what's wrong.

Yes, I'm running in debug mode. I tried eliminating this function from the class definition and making it into a function defined in the main program, and it started working (with an error that I still need to fix, but not an exception that just locks everything up).

To Sebastiani: The way this problem has arisen and gotten more or less fixed (essentially without changing the program in any substantive way, just shuffling things around a bit) makes me think you're right about its being unsafe. But does that apply in general to dynamic memory allocation for an array? I mean, dynamic memory allocation seems like an option that one should use when called for... ?

Also, I assume that since vectors aren't basic data types that they themselves get memory dynamically allocated--although the code regulating vectors (and strings) has obviously been created by experienced programmers with knowledge about possible problems and how to avoid them.

But that would also mean that there are ways to allocate memory dynamically that have some additional safety measures (?).

This function returning a vector is obviously incomplete, but I wondered if this basic technique is just fundamentally better:

In terms of memory management, yes. However, you probably want to pass the Carddeck by non-const reference since the complete implementation of this function will presumably modify it, and if not, then pass by const reference since a copy is probably unnecessary.

Incidentally, you might want to consider throwing an exception instead of printing an error message in this function and returning a vector. If you really want to return a vector, returning an empty vector to signal an error is probably better since the caller can check for an error by calling the empty() member function.

Also, note that you do not need to name an object that you will immediately return, e.g.,

Code:

return vector<int>(numCards, 0);

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.