Hello all,
my question is basically wheather it's possible to
have nested templates .. I mean the following
if there are one templ. class and one global templ. function
is it possible to specialize the function for say <int>
but this for all possible classes (from class template)
the code is here
template <typename>
class X;
template <typename type>
void foo(X<type> &);
template <typename type = int>
class X
{
friend void foo<type>();
type x;
public:
X(type x) : x(x) {}
};
template <typename type>
void foo(X<type> & x)
{
cout << "with type = " << typeid(type).na me() << endl;
cout << x.x << endl;
}
template <> // this seems not ok
template <typename type> // but i need "type" for X
void foo<void>(X<typ e> & x)
{
cout << "this is void overload" << endl;
cout << x.x << endl;
}
int main()
{
X<> x(1); // int
foo<void>(x);
return EXIT_SUCCESS;
}
Regards, Daniel
g++ --version
g++ (GCC) 4.0.2
my question is basically wheather it's possible to
have nested templates .. I mean the following
if there are one templ. class and one global templ. function
is it possible to specialize the function for say <int>
but this for all possible classes (from class template)
the code is here
template <typename>
class X;
template <typename type>
void foo(X<type> &);
template <typename type = int>
class X
{
friend void foo<type>();
type x;
public:
X(type x) : x(x) {}
};
template <typename type>
void foo(X<type> & x)
{
cout << "with type = " << typeid(type).na me() << endl;
cout << x.x << endl;
}
template <> // this seems not ok
template <typename type> // but i need "type" for X
void foo<void>(X<typ e> & x)
{
cout << "this is void overload" << endl;
cout << x.x << endl;
}
int main()
{
X<> x(1); // int
foo<void>(x);
return EXIT_SUCCESS;
}
Regards, Daniel
g++ --version
g++ (GCC) 4.0.2
Comment