L
Lionel B
Greetings.
The following code compiles ok and does what I'd expect it to do:
[apologies for the lack of indentation... Google Groups 2 Beta bug
reported]
---------- START CODE ----------
// test.cpp
#include <iostream>
template <class T> struct A
{
A();
};
A<int>::A()
{
std::cout << "Template parameter is \"int\"" << '\n';
}
A<long>::A()
{
std::cout << "Template parameter is \"long\"" << '\n';
}
int main()
{
A<int> a1;
A<long> a2;
return 0;
}
---------- END CODE ----------
The program outputs:
Template parameter is "int"
Template parameter is "long"
So far so good... now I would like to do the same, but there is a
second template parameter and I only want to specialise on the first:
---------- START CODE ----------
// test.cpp
#include <iostream>
template <class T, class R> struct A
{
A();
};
template <class R> A<int, R>::A() // line 10
{
std::cout << "First template parameter is \"int\"" << '\n';
}
template <class R> A<long, R>::A() // line 15
{
std::cout << "First template parameter is \"long\"" << '\n';
}
int main()
{
A<int, int> a1;
A<long, int> a2;
return 0;
}
---------- END CODE ----------
My compiler (gcc 3.3.3 cygwin special) throws this out with:
g++ test.cpp -o test.exe
test.cpp:10: error: parse error before `)' token
test.cpp:15: error: parse error before `)' token
I can't figure out quite what the syntax should be to specialise on the
first template parameter only. It would seem that A<int, R>::A() is
still a template function, but my compiler doesn't like the "obvious"
definition:
template <class R> A<int, R>::A()
Any help appreciated,
The following code compiles ok and does what I'd expect it to do:
[apologies for the lack of indentation... Google Groups 2 Beta bug
reported]
---------- START CODE ----------
// test.cpp
#include <iostream>
template <class T> struct A
{
A();
};
A<int>::A()
{
std::cout << "Template parameter is \"int\"" << '\n';
}
A<long>::A()
{
std::cout << "Template parameter is \"long\"" << '\n';
}
int main()
{
A<int> a1;
A<long> a2;
return 0;
}
---------- END CODE ----------
The program outputs:
Template parameter is "int"
Template parameter is "long"
So far so good... now I would like to do the same, but there is a
second template parameter and I only want to specialise on the first:
---------- START CODE ----------
// test.cpp
#include <iostream>
template <class T, class R> struct A
{
A();
};
template <class R> A<int, R>::A() // line 10
{
std::cout << "First template parameter is \"int\"" << '\n';
}
template <class R> A<long, R>::A() // line 15
{
std::cout << "First template parameter is \"long\"" << '\n';
}
int main()
{
A<int, int> a1;
A<long, int> a2;
return 0;
}
---------- END CODE ----------
My compiler (gcc 3.3.3 cygwin special) throws this out with:
g++ test.cpp -o test.exe
test.cpp:10: error: parse error before `)' token
test.cpp:15: error: parse error before `)' token
I can't figure out quite what the syntax should be to specialise on the
first template parameter only. It would seem that A<int, R>::A() is
still a template function, but my compiler doesn't like the "obvious"
definition:
template <class R> A<int, R>::A()
Any help appreciated,