My assignment is to make a template class for store heterogeneous collections. There is a test code for the assignment and I have some problem with the 4th test.
Here is the template class: https://imgur.com/rx3yRy0
Here is the testclass: https://imgur.com/i58s0eX
/// The problematic test part: Checking the Traverse
TEST(Test4, heterogen) {
HeteroStore<TestClass> t1;
t1.add(new TestClass1(1));
t1.add(new TestClass1(2));
t1.add(new TestClass2("Hello"));
t1.add(new TestClass2("World"));
t1.add(new TestClass1(3));
t1.add(new TestClass2("Bye"));
std::stringstream ss;
TestClassPrint print(ss);
t1.traverse(print); //This is where the program stops working
}
///The template function
template<class func>
void traverse(func F)const{
for (size_t i=0; i<db; i++)
if (t[i]!=NULL)
F(t[0]);
}
The output: https://imgur.com/uHrhRMj
User contributions licensed under CC BY-SA 3.0