A
Ashley
I'm trying to unroll a loop that prints down numbers from the given
number down to 0. I get the following error on Sun C++ 5.5 Patch
113817-12.
-------------------------
"tmp.cpp", line 15: Error: explicit specialization is not allowed in
the current scope.
"tmp.cpp", line 24: Where: While specializing
"printDownContainer<int>".
"tmp.cpp", line 24: Where: Specialized in non-template code.
"tmp.cpp", line 24: Error: Template parameter T requires a type
argument.
-------------------------
How can I correct this? I want to generalize the type of the counter
i. Here's the code.
-------------------------
#include <iostream>
template< typename T >
struct printDownContainer
{
template< T i >
struct printDown {
static void run(void) {
std::cout << i << "\n";
printDown< i - 1 >::run();
}
};
template< >
struct printDown< 0 > {
static void run(void) {
std::cout << 0 << "\n";
}
};
};
int main(void)
{
printDownContainer< int >:rintDown< 10 >::run();
return 0;
}
number down to 0. I get the following error on Sun C++ 5.5 Patch
113817-12.
-------------------------
"tmp.cpp", line 15: Error: explicit specialization is not allowed in
the current scope.
"tmp.cpp", line 24: Where: While specializing
"printDownContainer<int>".
"tmp.cpp", line 24: Where: Specialized in non-template code.
"tmp.cpp", line 24: Error: Template parameter T requires a type
argument.
-------------------------
How can I correct this? I want to generalize the type of the counter
i. Here's the code.
-------------------------
#include <iostream>
template< typename T >
struct printDownContainer
{
template< T i >
struct printDown {
static void run(void) {
std::cout << i << "\n";
printDown< i - 1 >::run();
}
};
template< >
struct printDown< 0 > {
static void run(void) {
std::cout << 0 << "\n";
}
};
};
int main(void)
{
printDownContainer< int >:rintDown< 10 >::run();
return 0;
}