On 20.03.2019 23:42,
saulmartin...@gmail.com wrote:
> Hi,
> I just started learning c++, in my classroom the teacher wrote code of static list using class template, the list is based on an array, it works fine for what was tried, integers, floats, strings and as well for abstract data (classA), because he wrote also a class that has one integer, one float and one string so the class template list is also able to work with that abstract data type, everything was tried in the same console application and worked fine, my questions for abstract data type, how or where this list store those data, I moreless understand how it works with the template for integers, floats and strings but I can not understand how it does for the 3 data types at the same time, I mean in a classA datatype together.
> For example if data is integer with the template is like cresting an integer array, for floats it is like creating a float array, same for string, but what about classA datatype, does it create 3 arrays? one for integer, one for float and one for string? or it is a single array containing addresses to each of classA instances?
No, it's a single array of ClassA instances directly as array items.
Each ClassA item contains an int, a string and a float.
By the way, ClassA, as presented in the code below, is /not/ abstract.
Also, preferably use the default floating point datatype in C++, double.
E.g., the literal 3.14 is of type double.
If ClassA were abstract then one couldn't create an array of classA
instances.
> Please help, I want to understand and I can not ask the teacher because it was supposed he already explained.
You should be able to ask your teacher to clarify things.
I think in a case where the teacher refuses to explain or is generally
inaccessible, I would first consult with other students in the class.
If that happens often enough, also with other students, then the
students, as a body, may try to complain about the teacher.
Cheers!,
- Alf