Topic: template function with visual C++


Author: lardinois <ylardinois@cirb.irisnet.be>
Date: 2000/02/16
Raw View
I have the following problem with VisualC++ 6.0
I have the following template function definition:


template <class T> T* func(std::map<std::string,T*> f);
...

when the compiler should compile the 'instantiation' of this function
with

std::map<std::string,MyClass *> ff;
MyClass* res = func(ff); // here the error

I receive an internal error of the compiler when compiling the 'error
line'
Is the syntax correct for the standard C++?
Did anyone have the same problem with the visual C++ compiler?
Thanks for any help

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: Jerry Coffin <jcoffin@taeus.com>
Date: 2000/02/16
Raw View
In article <38A914D4.3FD94D53@cirb.irisnet.be>,
ylardinois@cirb.irisnet.be says...
> I have the following problem with VisualC++ 6.0
> I have the following template function definition:
>
> template <class T> T* func(std::map<std::string,T*> f);

In theory this should work, but as you've noted the Microsoft compiler
doesn't like it.  An obvious cure would be to change to:

template <class T> T func(std::map<std::string, T> f);

This way, when you instantiate it, "T" is the type "pointer to
MyClass" and everything works fine.

I think your syntax is correct, but is simply pushing beyond what VC++
6 is capable of dealing with.

--
    Later,
    Jerry.

The universe is a figment of its own imagination.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]