Basically, I have a Linked List which implements a display()
function that simply loops throught he elements and prints out their values.
I wanted to do it like this:
void List::display( std::string type )
{
switch(type)
{
// Do stuff...
The compiler immediately complained. My teacher said this would be because the string is not known at compile-time, resulting in an error. That explanation sounds a little iffy, but he suggested that I use enums. So I researched it and it says that explicit string to enums doesn't work. Something like
class List
{
enum type
{
HORIZONTAL = "inline"
VERTICAL = "normal"
}
and then, I really don't know.
The enum type
is a part of the List class, as well as the function display()
. This again looks like a really crappy solution. Nevertheless, I want to know if this approach is possible.
How could I set the enum in the main function at the same time I call display()? Like so
int main( void )
{
display("normal");
Of course, easier approaches are very welcome. In general, how do I declare/pass an enum to a function, if possible?