The design reason for having two internal std::list
containers is not clear. Only one of the list
containers is filled, dependent on the enum type _val
value passed to the
addtolist(std::string name, type _val, int b);
constructor. In order to have a non-empty list1
container for an INVALID
type, the body of the constructor will have to change accordingly. In other words, the second object ob2
has elements for list2
, because container number two is the only list
that has been populated.
If in doubt, check the list1.empty()
condition for both enum type
values, which is not really necessary since the list1.size()
value is already shown as zero for the INVALID
type. Ultimately the for
loop which traverses list1
for the INVALID
type is behaving exactly as it supposed to for an empty container.
One way to always have list1
filled, is to move the list1 for loop
above the if statement logic that checks for the enum type
. This is only an example. The actual design modification is up to the OP.
addtolist::addtolist( std::string name, type _val, int range )
{
name = name;
val = _val;
int i;
for(i=0;i<=range;i++)
{
list1.push_back(i);
}
if (val==VALID)
{
//
// for loop that prints list1 content and other code follows as before
//
.
.
.