Templates in .NET

G

Guest

I'm attempting to convert an existing VC6++ project to .NET.

The project makes use of Microsoft's old VisSDK and this uses templates all
over the place, generating 100's of errors.

One common error is to do with this new 'typename' keyword - are there any
#pragma's, or compiler options, that force the compiler to use the old method
?

Whilst I've used templates, I've never designed one myself and am a bit
lost. For example, I get the following warning :-

c:\Projects\VisSDK\inc\VisStlWrappers.h(163) : warning C4346:
'std::map<_Kty,_Ty,_Pr,_Alloc>::value_compare' : dependent name is not a type
prefix with 'typename' to indicate a type

The code fragment is :-

template<class _K, class _Ty, class _Pr = std::less<_K>,
class _A = std::allocator<_Ty> >
class CVisStlMap {
public:
typedef CVisStlMap<_K, _Ty, _Pr, _A> T_This;
typedef std::map<_K, _Ty, _Pr, _A> T_Map;
typedef std::pair<const _K, _Ty> value_type;

typedef T_Map::_Kfn _Kfn; <---line 163

Where does "typename" go ???

TTFN,
Jon
 
V

Vladimir Nesterovsky

The code fragment is :-
template<class _K, class _Ty, class _Pr = std::less<_K>,
class _A = std::allocator<_Ty> >
class CVisStlMap {
public:
typedef CVisStlMap<_K, _Ty, _Pr, _A> T_This;
typedef std::map<_K, _Ty, _Pr, _A> T_Map;
typedef std::pair<const _K, _Ty> value_type;

typedef T_Map::_Kfn _Kfn; <---line 163

Where does "typename" go ???

typedef typename T_Map::_Kfn _Kfn;
 
G

Guest

Vladimir Nesterovsky said:
typedef typename T_Map::_Kfn _Kfn;

Thats what I initially assumed too. However the compiler generates exactly
the same error :-(

TTFN,
Jon
 
C

Carl Daniel [VC++ MVP]

Jon said:
Thats what I initially assumed too. However the compiler generates
exactly the same error :-(

1. There are probably somewhere betweens tens and hundreds of places that
'typename' needs to be inserted.
2. Are you sure you showed the right code snippet? The error you quoted is
griping about ::value_compare, but there's no reference to ::value_compare
anywhere in the code you posted.
3. Unfortunately, there's no way to force VC7.1 to revert to VC6's bad
habits - this change was mandated by the C++ standard 6 years ago and VC
finally became compliant in this regard with VC7.1.

I just downloaded VisSDK - it was actually just updated in February of this
year, but it still only supports VC6. If you can post a small but complete
example that compiles with VC6 but not with VC7.1 I might be able to figure
out what needs to be fixed up in the VisSDK code.

-cd
 
G

Guest



Hi Carl,
1. There are probably somewhere betweens tens and hundreds of places that
'typename' needs to be inserted.

Absolutely. But at this stage I don't know how many of the errors are caused
by previous errors.

This particular project goes back a few years. The actual image aquisition
side of things have long since been replaced by DirectShow but the project
still uses the image classes from the VisSDK as that would have been a lot of
work to change.
2. Are you sure you showed the right code snippet? The error you quoted is
griping about ::value_compare, but there's no reference to ::value_compare
anywhere in the code you posted.

The text was literally cut and paste.
3. Unfortunately, there's no way to force VC7.1 to revert to VC6's bad
habits -


:-( Shame ; I can understand it from the point of view of Microsoft as they
get plenty of flack when they don't do things the "right" way, but lack of
some mechanism to enable backwards compatability is also a problem.
I just downloaded VisSDK - it was actually just updated in February of this
year, but it still only supports VC6. If you can post a small but complete
example that compiles with VC6 but not with VC7.1 I might be able to figure
out what needs to be fixed up in the VisSDK code.

Create a new VC6 project using the vision app wizard, compile and run it and
alls well, Open the project in dot net and try and compile it.

If I can still use the VisSDK with nothing more than a few extra
"typename"'s or something equally straightfroward then that'd be great.
However it it requires anything more cpomplicated than that then since I'm
only using the basic image class's then I guess it'd be easier just to
replace those.

Thanks,
Jon
 
C

Carl Daniel [VC++ MVP]

Jon said:
Create a new VC6 project using the vision app wizard, compile and run
it and alls well, Open the project in dot net and try and compile it.

Unfortunately, I don't have VC6 loaded anymore - haven't used it for years.
If I can still use the VisSDK with nothing more than a few extra
"typename"'s or something equally straightfroward then that'd be
great. However it it requires anything more cpomplicated than that
then since I'm only using the basic image class's then I guess it'd
be easier just to replace those.

That could well be the case.

-cd
 
J

James Curran

Carl Daniel said:
2. Are you sure you showed the right code snippet? The error you quoted is
griping about ::value_compare, but there's no reference to ::value_compare
anywhere in the code you posted.

In vc7.1, in the map template definition in the include file <map>,
there is the definition:

typedef typename _Mybase::value_compare value_compare;

I wonder if in vc7.0 the "typename" was left off that typedef.....

--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top