By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 1,478 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

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

P: 1
hi can anyone help me??

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

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3. template < Typename T>
  4. bool T xor(const T& a, const T& b)
  5.  { return !(a&&b)&&(a||b); }
  6. int main()
  7. { char a, b;
  8.  cout<<" enter ";
  9.  cin>>a, b;
  10.  cout<<xor(a,b);
  11.  return 0;
  12. }
[Error] 'Typename' has not been declred
[Error] expected initializer before 'xor' token
[Error] expected primary-expression before 'xor' token
Jan 29 '14 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Jan 29 '14 #2

Expert 100+
P: 2,391
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.
Jan 29 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.