V
Victor Bazarov
Schüle Daniel said: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)
Uh... I am not sure I understand what you're trying to accomplish.
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>();
There is no 'foo' without arguments! Did you mean
friend void foo<type>(X&);
?
type x;
public:
X(type x) : x(x) {}
};
template <typename type>
void foo(X<type> & x)
{
cout << "with type = " << typeid(type).name() << endl;
cout << x.x << endl;
}
template <> // this seems not ok
template <typename type> // but i need "type" for X
OK. So, you're trying to define a specialisation of 'foo' on 'void'
so that the argument is now a template. IOW, you're defining another
template here... That's not possible. Besides, there are no partial
specialisations of function templates.
Why do you think you need this construct?
void foo<void>(X<type> & 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
V