In your code there are a lot of raw pointers where 'normal' variables could be used, and raw pointers in general are better avoided - or replaced with "gsl::owner<T*>", if you want to take advantage of the gsl library.
You also tend to declare all the variables in a bunch at the beginning of your functions, which is usually discouraged:
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#nr1-dont-all-declarations-should-be-at-the-top-of-a-function
It seems you could substitute a std::vector<Vehicle*> for your std::list<Vehicle*>, which would have better performances.
Btw, using a '1' (digit) in the middle of a variable name ("t1ptr") could be confusing, since it really looks like a 'l' (letter).
Do you really need to use classes Vehicle and Tank1 polymorphically? So far, it doesn't seem so beneficial...
Anyway, you could consider to use dynamic_cast<> to explicitely cast between the two types, instead of simply assign pointers from one variable of a type to another of the other type.
Stating clearly what you mean to do, makes your code more readable, I guess.
I mean this piece of code:
1 2 3 4 5 6 7 8
|
list<Vehicle*> UnscoredVehicles;
Vehicle* vptr;
Tank1* t1ptr;
. . .
t1ptr = new Tank1(num);
num++;
vptr = t1ptr;
UnscoredVehicles.push_back(vptr);
| |
could simply become:
1 2 3 4
|
list<Vehicle*> UnscoredVehicles;
...
UnscoredVehicles.push_back(dynamic_cast<Vehicle*>(new Tank1(num)));
num++;
| |
Please remember std::default_random_engine is implementation-defined; it means you cannot be sure what engine are you really dealing with (that's nothing bad in that, of course, but it's up to you to initialize it properly).
I'm not into math, but are you sure you need a std::normal_distribution<double> in yout Tank1(int) constructor?
https://en.wikipedia.org/wiki/Normal_distribution
It seems a std::uniform_real_distribution<> could do the trick.
You'd better re-read your code and eliminate incongruences like:
1 2
|
t = genVee(*gen1ptr);
t = 1;
| |
- - -
Apart from that, could you explain what your code should do?
It's not a problem to make it work, but it's not clear what it is expected to do.