newtoprogramming123
newtoprogramming123

Reputation: 37

Use a template to handle integers, strings, and arrays of strings

As the title states, I am trying to use a class template with member functions to handle other functions that use integers, strings, and arrays of user-defined strings from the command line. The file I am working with is:

This file works for functions that are using integers and strings, but not for a function that processes an arbitrary array of user-defined strings from the command line. The error message when I compile for that function is:

What am I doing wrong? As I said before, the work I have in the header file will work for the integers and strings, but it won't work for the array of strings. Any ideas?

Upvotes: 0

Views: 73

Answers (2)

David
David

Reputation: 1530

LessThanOnly defines an operator< but not an operator> However MiniMax uses both operators.

Either define an operator> or switch the logic in MiniMax::observe to be :

  if (t < min)
      min = t;
  if (max < t)
      max = t;

Upvotes: 1

Barry
Barry

Reputation: 303377

The error message explains what the problem is:

./minimax.h:65:13: error: invalid operands to binary expression ('const LessThanOnly' and
      'LessThanOnly')
      if (t > max)
          ~ ^ ~~~

Here's a hint. What is the name of the types you are trying to compare? What is the operation you are doing to compare them? How do you fix it?

Upvotes: 0

Related Questions