i'm testing out a template function i created for a header file i'm writing, but it will not compile for some reason. it's giving me problems with iosfwd, although i'm not using it.

#include <iostream>

using namespace std;

template <class LOGICAL_AND>
LOGICAL_AND __and(x, y)
{
	return x==y ? 1 | 0;
}


int main()
{
	int a = 24;
	int b = 7;
	int c = 12;
	int d = 12;

        char x[2]; //use to close program and show values

	cout << __and(a,b) << endl;
	cout << __and(c,d) << endl;

	cin.get(x,2);

	return 0;
}

i would post up the errors but theres around 147 of them e.e

any ideas?

Recommended Answers

All 10 Replies

You want :

template<typename T>
bool logicalAnd(T x, T y){
 return x == y;
}
int main(){
 int x = 3, y = 5;
 cout << logicalAnd(x,y) << endl;
}

Btw, you probably don't want to use double underscore as an identifier because its reserve

firstly, you forogot the using directive. cout would be uindefined without it.

secondly it still give me the errors described. i think it's the template declarator that may be incorrect (not the function but what ever the code used to create the definition for template)

thirdly my syntax is correct:

return x==y ? 0 | 1

returns 0 if x != y and 1 if x == y see c++ operators for ?

Just an observation. Using tokens/keywords with leading double underscores, such as __AND, are reserved for the compiler and system library implementer. NEVER (I repeat that - NEVER) use them in your own code, otherwise you are likely to encounter some very weird error situations with names (and macro name) collisions! If you are writing a compiler and the associated support libraries, then that is your choice. If not, then DO NOT DO THIS! Trust me, I have had to deal with a number of these problems in the past, and figuring out why things went sideways was not a fun exercise!

ok i removed the underscores from my code, but it still is giving me errors with iosfwd.


1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(41) : error C2146: syntax error : missing ';' before identifier 'fpos_t'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(41) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(42) : error C2143: syntax error : missing ';' before 'const'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(42) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(42) : error C2734: 'std::_BADOFF' : const object must be initialized if not extern
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(186) : error C2061: syntax error : identifier '_In_count_'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(295) : see reference to class template instantiation 'std::char_traits<_Elem>' being compiled
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(187) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(188) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(197) : error C2061: syntax error : identifier '_In_z_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(208) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(209) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(209) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(212) : warning C4183: 'copy': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(214) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(214) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(214) : error C2086: 'int std::char_traits<_Elem>::_Elem' : redefinition
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : see declaration of 'std::char_traits<_Elem>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(214) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(214) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(215) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(216) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(216) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(224) : warning C4183: '_Copy_s': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(226) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(226) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(226) : error C2373: 'std::char_traits<_Elem>::_Elem' : redefinition; different type modifiers
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : see declaration of 'std::char_traits<_Elem>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(226) : error C2061: syntax error : identifier '_In_count_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(227) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(228) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(228) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(234) : warning C4183: 'find': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C2086: 'int std::char_traits<_Elem>::_Elem' : redefinition
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : see declaration of 'std::char_traits<_Elem>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(237) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(238) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(239) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(239) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(242) : warning C4183: 'move': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(244) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(244) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(244) : error C2086: 'int std::char_traits<_Elem>::_Elem' : redefinition
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : see declaration of 'std::char_traits<_Elem>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(244) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(244) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(245) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(246) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(246) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(258) : warning C4183: '_Move_s': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(260) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(260) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(260) : error C2086: 'int std::char_traits<_Elem>::_Elem' : redefinition
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : see declaration of 'std::char_traits<_Elem>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(260) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(260) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(261) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(262) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(262) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(268) : warning C4183: 'assign': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(270) : error C2143: syntax error : missing ';' before '__cdecl'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(270) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(270) : error C2086: 'int std::char_traits<_Elem>::_Elem' : redefinition
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(207) : see declaration of 'std::char_traits<_Elem>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(270) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(271) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(273) : warning C4183: 'to_char_type': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(275) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(275) : error C2143: syntax error : missing ',' before '&'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(323) : error C2061: syntax error : identifier '_In_count_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(324) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(325) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(331) : error C2061: syntax error : identifier '_In_z_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C2377: 'std::char_traits<wchar_t>::_Elem' : redefinition; typedef cannot be overloaded with any other symbol
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(301) : see declaration of 'std::char_traits<wchar_t>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(339) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(340) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(340) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(340) : warning C4183: 'copy': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(345) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(345) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(345) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(345) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(346) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(347) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(347) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(347) : warning C4183: '_Copy_s': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(354) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(354) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(354) : error C2373: 'std::char_traits<wchar_t>::_Elem' : redefinition; different type modifiers
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(338) : see declaration of 'std::char_traits<wchar_t>::_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(354) : error C2061: syntax error : identifier '_In_count_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(355) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(356) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(356) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(356) : warning C4183: 'find': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(362) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(362) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(362) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(362) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(362) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(363) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(364) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(364) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(364) : warning C4183: 'move': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(369) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(369) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(369) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(370) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(371) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(371) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(371) : warning C4183: '_Move_s': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(378) : error C2143: syntax error : missing ';' before '*'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(378) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(378) : error C2061: syntax error : identifier '_Out_cap_'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(378) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(379) : error C2143: syntax error : missing ')' before '{'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(379) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(379) : warning C4183: 'assign': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(384) : error C2143: syntax error : missing ';' before '__cdecl'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(384) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(385) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(385) : warning C4183: 'to_char_type': missing return type; assumed to be a member function returning 'int'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(389) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(389) : error C2143: syntax error : missing ',' before '&'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(328) : error C2065: '_First1' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(328) : error C2065: '_First2' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(328) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(334) : error C2065: '_First' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(342) : error C2065: '_First1' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(342) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(342) : error C2065: '_First2' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(342) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(350) : error C2065: '_First1' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(350) : error C2065: '_Size_in_words' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(350) : error C2065: '_First2' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(350) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(350) : error C3861: '_CRT_SECURE_WMEMCPY': identifier not found
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(351) : error C2065: '_First1' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(358) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(358) : error C2146: syntax error : missing ')' before identifier '_Elem'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(358) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(358) : error C2059: syntax error : ')'
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(366) : error C2065: '_First1' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(366) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(366) : error C2065: '_First2' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(366) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(374) : error C2065: '_First1' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(374) : error C2065: '_Size_in_words' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(374) : error C2065: '_First2' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(374) : error C2065: '_Count' : undeclared identifier
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(374) : error C3861: '_CRT_SECURE_WMEMMOVE': identifier not found
1>c:\program files (x86)\microsoft visual studio 9.0\vc\include\iosfwd(374) : fatal error C1003: error count exceeds 100; stopping compilation
1>Build log was saved at "file://c:\Users\LdaXy\Documents\Visual Studio 2008\Projects\test\test\Debug\BuildLog.htm"
1>test - 147 error(s), 14 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

here is a list of errors. please noe that this does not occur when i do not use template.

Well, this is pretty simple code, and other than the underscore issue, I don't see why you are having this problem. Have you posted your code in its entirety, and altogether?

yes that is the complete code there. i should mention though, that a few weeks ago Visual studio wouldn't work and complained that the compilers and includes were missing. (even though i have he windows sdk installed.) creating anything else works just not the template declarator.

yes that is the complete code there. i should mention though, that a few weeks ago Visual studio wouldn't work and complained that the compilers and includes were missing. (even though i have he windows sdk installed.) creating anything else works just not the template declarator.

Ok. Important information here! If VS thinks your system is fubar, then you should reinstall Visual Studio! Root cause analysis - something everyone who writes computer software should learn, FIRST! :-)

problem is though, i've done that 6-8 times before this error occurred. i'm extremely proficient at tech support and after repeating the same process 6 times with the problem still persisting, it doesn't make much sense to try it again.

maybe i'll switch to codeblocks and see if it works.

firstly, you forogot the using directive. cout would be uindefined without it.

secondly it still give me the errors described. i think it's the template declarator that may be incorrect (not the function but what ever the code used to create the definition for template)

thirdly my syntax is correct:

return x==y ? 0 | 1

returns 0 if x != y and 1 if x == y see c++ operators for ?

I assumed you were smart enough to figure the implicit stuff out. Btw, you're trying to use ternary but you are using the wrong syntax, you want, return x == y ? 1 : 0 but even more simpler, just return x == y

This

#include <iostream>

using namespace std;

template<class T>
bool logicalAnd(T x, T y){
	return !(x == y);
}

int main(){
	int x = 3, y = 5;
	cout << logicalAnd(x,y) << endl;
}

compiled without any errors or warnings using g++ -Wall , so if it doesn't compile under VS it's most likely something with your installation, or something VS-specific.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.