template<typename T> void foo();
template<typename T> void foo<T*>();
and in main()
foo<int>();
foo<int*>();
Where have I gone wrong?
thanks
Peter
There's no such thing in C++ as partial specialization of template
functions. Partial specialization is only applicable to class templates. Try
to make do with overloading and/or explicit specialization.
--
Best regards,
Andrey Tarasevich
Brainbench C and C++ Programming MVP
I thought that might be the case and admittedly I have no great
application for such functions? In the past I've used overloading
foo(T())
as in std::distance but why is this not allowed. It could prevent
duplication of code such as,
int read_int();
int* read_int_ptr();
etc
Partial specialisation of functions can be emulated with
classes.
template<class T> struct readT
{
T storage; // or other implementation
readT() { cin >> storage; }
operator T() { return storage; }
};
template<class T> struct readT<T*>
{
T* pointer;
readT() { pointer = new T; cin >> *pointer; }
operator T*() { return pointer; }
};
int main()
{
int i = readT<int>();
double *pd = readT<double*>();
delete pd;
return i;
}
Victor
--
Please remove capital A's from my address when replying by mail
namespace Private { // Implementation
template <typename T>
struct Type2Type
{
typedef T OriginalType;
protected:
~Type2Type() {}
};
template <typename T> void foo( Type2Type<T> )
{ /* your implementation for type T */ }
template <typename T> void foo( Type2Type<T*> )
{ /* your implementation for type T pointer */ }
} // end namespace Private
// This is the only one seen by your program
template <typename T> void foo( )
{
return( Private::foo( Private::Type2Type<T>( ) ) );
}
Now you have a single interface and multiple implementations based upon the
underlying type T. You can even differentiate between const T's and T's.
There is a lot of power in using the class Type2Type.
Hope this is useful - I use it often.
--Regard,
Shane
"Pete Seymour" <pe...@seymour17.freeserve.co.uk> wrote in message
news:917937f7.02090...@posting.google.com...
"Shane Neph" <eucli...@hotmail.com> wrote in message
news:Nsvd9.8759$JJ1....@nwrddc02.gnilink.net...