Please share your thoughts on Member Function Templates 
July 23rd, 2005, 04:50 AM
| | | Please share your thoughts on Member Function Templates
Hi All C++ Experts
Can anybody share some of your thoughts in Member Function Templates
implementation.Can you also give some example on it
Best Regards
Raj | 
July 23rd, 2005, 04:51 AM
| | | Re: Please share your thoughts on Member Function Templates
Rajan wrote:[color=blue]
> Can anybody share some of your thoughts in Member Function Templates
> implementation.Can you also give some example on it[/color]
What exactly would you like to know? Here is an example:
class ConvertibleToAPointer {
// ...
public:
template<class T> operator T*();
};
Here is another example:
class CanWorkOnAPointer {
// ...
public:
template<class T> void workOn(T*);
};
As to thoughts, here is one: unfortunately some compilers don't support
those well, as I discovered today. But then again, they just have some
bad template support in general...
V | 
July 23rd, 2005, 04:51 AM
| | | Re: Please share your thoughts on Member Function Templates
Hi
Victor you are correct , i was having code like this
class ConvertibleToAPointer {
// ...
public:
template<class T> operator T*();
};
void fun(char *x)
{}
main()
{
ConvertibleToAPointer obj;
fun(obj);
}
so this code is not compiling . i think my compiler is not supporting
member template function.
Is there any get around way of doing this.
regards rajendra | 
July 23rd, 2005, 04:52 AM
| | | Re: Please share your thoughts on Member Function Templates
Rajan wrote:[color=blue]
> Victor you are correct , i was having code like this
> class ConvertibleToAPointer {
> // ...
> public:
> template<class T> operator T*();
> };
>
>
> void fun(char *x)
> {}
>
> main()
> {
> ConvertibleToAPointer obj;
> fun(obj);
>
> }
>
> so this code is not compiling . i think my compiler is not supporting
> member template function.
>
> Is there any get around way of doing this.[/color]
Try to specify the type explicitly:
class ConvertibleToAPointer {
public:
template<class T> T* convert2ptr() { return 0; }
};
void fun(char* x) {}
int main()
{
ConvertibleToAPointer obj;
fun(obj.convert2ptr<char>());
}
If your compiler has other quirks, you might consider posting questions
about them to that compiler's newsgroup (if it exists, of course).
V | 
July 23rd, 2005, 04:52 AM
| | | Re: Please share your thoughts on Member Function Templates
Victor, Rajan is using VC6.
Rajan, As I said earlier, VC6 is known to have issues with template
code, especially member function templates. You need to upgrade your
compiler. | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,662 network members.
|