Hi there.
I tried to compile the following code, and ran into a problem I do not understand:
// Begin of testfile
template <unsigned i1, unsigned i2>
class TestClass
{
public:
template <char c1, char c2, unsigned i3, unsigned i4, unsigned i5, unsigned i6>
void doSomething(const TestClass<i3,i4>& other1, const TestClass<i5,i6>& other2);
};
template <unsigned i1, unsigned i2>
template <char c1, char c2, unsigned i3, unsigned i4, unsigned i5, unsigned i6>
void TestClass<i1,i2>::doSomething(const TestClass<i3,i4>& other1, const TestClass<i5,i6>& other2)
{
// do something here...
}
void doSomeStuff()
{
TestClass<1,2> t1;
TestClass<3,1> t2;
TestClass<3,2> t3;
t1.doSomething<'A','B'>(t2,t3);
}
template <unsigned i>
void doSomeStuff_template()
{
TestClass<i,2> t1;
TestClass<3,i> t2;
TestClass<3,2> t3;
t1.doSomething<'A','B'>(t2,t3);
}
int main()
{
doSomeStuff();
doSomeStuff_template<1>();
return 0;
}
// EOF
I am using g++ version 4.1.2 on Fedora Core 6, which compiles the first function call (to doSomeStuff), but fails in doSomeStuff_template<1>. The error message I get is:
testfile.cpp: In function ‘void doSomeStuff_template() [with unsigned int i = 1u]’:
testfile.cpp:37: instantiated from here
testfile.cpp:31: warning: left-hand operand of comma has no effect
testfile.cpp:31: error: no match for ‘operator>’ in ‘'B' > (0, t3)’
testfile.cpp:31: error: invalid use of member (did you forget the ‘&’ ?)
I would appreciate any hint as to why that happens.
Thanks,
Martin
I tried to compile the following code, and ran into a problem I do not understand:
// Begin of testfile
template <unsigned i1, unsigned i2>
class TestClass
{
public:
template <char c1, char c2, unsigned i3, unsigned i4, unsigned i5, unsigned i6>
void doSomething(const TestClass<i3,i4>& other1, const TestClass<i5,i6>& other2);
};
template <unsigned i1, unsigned i2>
template <char c1, char c2, unsigned i3, unsigned i4, unsigned i5, unsigned i6>
void TestClass<i1,i2>::doSomething(const TestClass<i3,i4>& other1, const TestClass<i5,i6>& other2)
{
// do something here...
}
void doSomeStuff()
{
TestClass<1,2> t1;
TestClass<3,1> t2;
TestClass<3,2> t3;
t1.doSomething<'A','B'>(t2,t3);
}
template <unsigned i>
void doSomeStuff_template()
{
TestClass<i,2> t1;
TestClass<3,i> t2;
TestClass<3,2> t3;
t1.doSomething<'A','B'>(t2,t3);
}
int main()
{
doSomeStuff();
doSomeStuff_template<1>();
return 0;
}
// EOF
I am using g++ version 4.1.2 on Fedora Core 6, which compiles the first function call (to doSomeStuff), but fails in doSomeStuff_template<1>. The error message I get is:
testfile.cpp: In function ‘void doSomeStuff_template() [with unsigned int i = 1u]’:
testfile.cpp:37: instantiated from here
testfile.cpp:31: warning: left-hand operand of comma has no effect
testfile.cpp:31: error: no match for ‘operator>’ in ‘'B' > (0, t3)’
testfile.cpp:31: error: invalid use of member (did you forget the ‘&’ ?)
I would appreciate any hint as to why that happens.
Thanks,
Martin