vectors and classes
Is there some sort of limitations of what kind must the datatype be if I create a vector from it? I made my own string class and now when I try to push_back a new string to my empty vector I get general protection fault while running.
Any guesses what might possibly cause this?
Here's the .cpp for my class (s & l are private - all functions public).
Vectors don't restrict the data type that they contain, the vector class is very general on that point so that we can use vectors in place of arrays. Chances are the problem is in how you are using the vector that causes the fault.
Try stepping through your code to find the exact operation that causes the fault and see what all values are at that point. You can pinpoint the problem and develop a fix for it easily this way.
I can't remember exactly, but I think I remember seeing somewhere that the vector template creates a copy of the data that gets inserted into it. What this means is that if your class does not have copy constructor defined for it, then the compiler generates a default one that may not be suitable for your needs. This could be causing the problem. Try making a copy constructor for your class and see if the problem goes away. Then again, this might not be the reason why things are failing.