2

At first, I thought that the error was because of having void minimax<Data>:: before the observe function, but when I removed it, that added more errors. Can anyone help me understand what the problem is here?

1 Answers1

2

Here's the chunk of code where you declare your member function:

void MiniMax<Data>::observe (const Data& t);

int getCount() const  {return count;}  

Do you see the difference between how you declared observe() here, versus getCount()?

Just change this to:

void observe (const Data& t);
Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • 1
    The problem is...when I take out the `MiniMax::`, it gives me 10 compilation errors. I should also mention that I am also working with a driver for this .h file. I'll edit the original post with that. – newtoprogramming123 May 14 '16 at 01:35
  • Right, so fix ***those*** compilation errors, instead. This is definitely wrong. All you've accomplished here is mess up the code so bad, that the compiler does not see the real compilation errors after trying to swallow this whopper. – Sam Varshavchik May 14 '16 at 01:36
  • And if by those "10 compilation errors" you're referring to your cpp file, the problem is very easy: you already defined the `observe()` member template function correctly, in the header file, so all of that "observe()" jazz in the cpp file is rubbish. Remove it completely. Also remove the constructor from the cpp file, and define it in the header file. Actually remove the entire cpp file. See http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – Sam Varshavchik May 14 '16 at 01:39
  • 1
    Oh! I'm sorry! I thought you meant change the function implementation name, not the declaration. That leaves me with another compilation error, which I am working on now. Thank you for your help. – newtoprogramming123 May 14 '16 at 01:40
  • And you need to remove the cpp file completely, and put the constructor in the header file also. See the linked question. – Sam Varshavchik May 14 '16 at 01:41
  • I have this error, because I am trying to use this template to pass in an int, string, and char: `error: in instantiation of member function`. Any idea what this is? – newtoprogramming123 May 14 '16 at 01:50
  • No, sorry, I'm not a mind reader. Given a [mcve], myself or many others on stackoverflow.com could probably figure it out, but based on something that vague: no idea. – Sam Varshavchik May 14 '16 at 01:53
  • I have revised with the revised version of the .h file. Here is the function that is causing the error: `string str;` `MiniMax mnmx;` `for (int i = 0; i < argc-1; ++i)` `{` `str = argv[i+1];` `mnmx.observe(str);` `}`This function takes this template, and uses a string. The template works for an integer, but not this function. The error I am getting is: ./minimax.h:56:15: error: assigning to 'int' from incompatible type 'const std::__1::basic_string' min = max = t; ^ ~ – newtoprogramming123 May 14 '16 at 04:20