C++
I'm making a template class called Container with only one problem.
part of the assignments requirement is that I have to have a function that will print the contents of the class.
The other part is that it must work with a structure.
I am unsure as to how I should get the print function to show the contents of a structure...
part of the assignments requirement is that I have to have a function that will print the contents of the class.
The other part is that it must work with a structure.
I am unsure as to how I should get the print function to show the contents of a structure...
Comments
eg
struct Location{
string street;
string country;
};
Location place;
place.street = "4th";
place.country = "Canada";
"I have to have a function that will print the contents of the class. "
like so:
This method works for any non-object variable type (numbers, chars, strings) but not for a struct.
I don't know of anyway to test a variable to see wether it is an object/struct other than trying to access one of its attributes, which will cause compile errors when used with non-objects.
I'm no stranger to OOP, and I understand C++ cannot automatically know whats in a struct.
Is there a way to determine if a variable is a struct?
like for an array you can do:
sizeof array / sizeof array[0];
and for a struct you can do:
sizeof location / sizeof location.here;
but this wont compile because of the template TYPE not always being a struct.