I can compile and run this program, but I don't really understand why I can't compile it when I remove the
template <int W>
void bar();
part from it. Calling functions of Testclass directly from main() is no problem, however I cannot call the template function bar() from another template function, testfunction(), in my case.
When I attempt to compile without the above-mentioned two lines, gcc 4.7 stops with "error: invalid operands of types '' and 'int' to binary 'operator<'" and I don't understand why and I understand even less why I can compile and run the program with these two lines added. Clang however doesn't compile any of the two versions. Can anyone explain to me what's going on here?
#include <iostream>
template <int T>
class Testclass {
public:
void foo(void) {
std::cout << T << std::endl;
}
template <int U>
void bar(void) {
std::cout << T << " " << U << std::endl;
}
};
template <int W>
void bar();
template <int V>
void testfunction( void ) {
Testclass<V> otherTestObj;
otherTestObj.foo();
otherTestObj.bar<4>();
}
int main() {
Testclass<1> testobject;
testobject.foo();
testobject.bar<2>();
testfunction<3>();
return 0;
}