Connecting Tech Pros Worldwide Help | Site Map

Please share your thoughts on Member Function Templates

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 04:50 AM
Rajan
Guest
 
Posts: n/a
Default 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


  #2  
Old July 23rd, 2005, 04:51 AM
Victor Bazarov
Guest
 
Posts: n/a
Default 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
  #3  
Old July 23rd, 2005, 04:51 AM
Rajan
Guest
 
Posts: n/a
Default 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

  #4  
Old July 23rd, 2005, 04:52 AM
Victor Bazarov
Guest
 
Posts: n/a
Default 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
  #5  
Old July 23rd, 2005, 04:52 AM
red floyd
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

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.