Greetings all... Below I have a sample program with the headers and cpp files listed. As you can see in the main routine, there are 5 function calls that are all very similar. They call 5 corresponding routines in the Classrooms class. Can I solicit solutions to making this one call, with variables or templates to reduce the calls, or at least have a single call with typing? The only thing I can't change is the access of the vectors in the Classrooms.h.
I've tried this with templates and to be honest damn near threw my keyboard through the monitor with frustration. Anybody can help?
Names.h
1 2 3 4 5
class Names {
public:
enumclass Enums : int { Jack, Jill, John, Judy, Jzee };
};
Names.cpp
#include "Names.h"
Students.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <algorithm>
#include <condition_variable>
#include "Names.h"
template <Names::Enums name_a> class Students {
public:
Students();
void PrintEnum();
};
template <Names::Enums name_a> Students<name_a>::Students() {
}
template <Names::Enums name_a> void Students<name_a>::PrintEnum() {
printf("%s: Enum value for name = %d\n", __func__, (int) name_a);
}
Since line 12 in main.cpp is going to throw an exception, I suppose you could just skip the subsequent function calls.
The only thing I can't change is the access of the vectors in the Classrooms.h.
And by this you mean... ?
Your design is very odd. I would expect a type named Names to be a collection of names, not a type masquerading as a namespace. I would expect a type named Students to represent a collection of students, not a single student parameterized on a particular value. I would expect a type named Classrooms to be represent multiple classrooms, not be a collection of containers of different types of students.
Based on what I see, my suggestion would be that the Students type should not be templated and that the Classrooms type should be refactored based on the changes to the Students type. (And better names should be chosen for the types.)
Thanks for the inputs... the sample code I presented in my post is only an example and not the real code. The actual code is much too complicated and expansive and sensitive to put on a post. All I am looking for is a possible solution, based on the example, of a way to consolidate the calls given the structures of the vectors and the fact that they're private in the Classrooms.h
Please don't focus on the classroom, student name thing. That's not the relevant part.