472,353 Members | 1,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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

Jul 23 '05 #1
4 1402
Rajan wrote:
Can anybody share some of your thoughts in Member Function Templates
implementation.Can you also give some example on it


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
Jul 23 '05 #2
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

Jul 23 '05 #3
Rajan wrote:
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.


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
Jul 23 '05 #4
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.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sat | last post by:
Hi, I have a simplified version of a problem that I am facing (hope I haven't oversimplified it). This code doesn't work now and I want to find...
3
by: Dave | last post by:
Hello all, I am trying to create a full specialization of a member function template of a class template. I get the following errors: Line...
1
by: Arne Petersen | last post by:
Hy, I've got a problem with member function templates compiled into libraries. I'm trying to get a library collection (coded for GNU gcc, where...
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func();...
9
by: Ian | last post by:
Can it be done? If so, what's the syntax. For example a full specialisation, template <typename T> struct X { template <typename C> void...
4
by: Joseph Turian | last post by:
Hi, What is the correct syntax to get the bar<T>::f<int, unsigned>() function to compile in the following fragment? Thanks, Joseph class...
11
by: chsalvia | last post by:
I've been programming in C++ for a little over 2 years, and I still find myself wondering when I should use polymorphism. Some people claim that...
8
by: Rahul | last post by:
Hi, Is there a way to partially specialize only a member function of a template class (not the whole class). e.g. template <typename A,...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.