template problem

Joined
Aug 27, 2008
Messages
2
Reaction score
0
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
 
Joined
Aug 27, 2008
Messages
2
Reaction score
0
Ok, I found out myself. I should have written

t1.template doSomething<'A','B'>(t2,t3);

in the second function. I have never seen that syntax before...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top