[Error] expected primary-expression before 'xor' token

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gretakola
    New Member
    • Jan 2014
    • 1

    [Error] expected primary-expression before 'xor' token

    hi can anyone help me??

    is this code i dont know if is right or not, i am new in c++

    Code:
    #include <iostream>
    using namespace std;
    template < Typename T>
    bool T xor(const T& a, const T& b)
     { return !(a&&b)&&(a||b); }
    int main()
    { char a, b;
     cout<<" enter ";
     cin>>a, b;
     cout<<xor(a,b);
     return 0;
    }
    [Error] 'Typename' has not been declred
    [Error] expected initializer before 'xor' token
    [Error] expected primary-expression before 'xor' token
    Last edited by Rabbit; Jan 29 '14, 07:22 PM. Reason: Please use [CODE] and [/CODE] tags when posting code or formatted data.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Your function returns a bool. What was the T for?

    Usually a modifier between the return type and the function name is a call convention specifier like __cdecl or some such.

    I suspect you intended to return bool (true/false) so just remove the T.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Consider line 5, logical-not (!) has a higher precedence than logical-and (&&). It is too hard (and error prone) to try and remember the precedence of operators that aren't used often; so I like to use enough parentheses to remove all doubt.

      Comment

      Working...