If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Vs6 to VS2008 Template Problem

Hi

I'm in the midst of porting an old VS6 project to VS2008/2010 and have hit a compilation problem associated with a template class. I would appreciate any comments or suggestions on reaching a resolution to the problem!

Re: Vs6 to VS2008 Template Problem

Originally Posted by rch83199

Hi

I'm in the midst of porting an old VS6 project to VS2008/2010 and have hit a compilation problem associated with a template class. I would appreciate any comments or suggestions on reaching a resolution to the problem!

It would help if you tell us what to compile to duplicate the error. To do that, you should put the entire code in one source file, not several files, or create a real project using those files.

The reason you need typename is that the compiler believes that "iterator" is a static member variable without the typename specifier. When you specify "typename", then you are telling the compiler that "iterator" is a type and not a static member variable.

Re: Vs6 to VS2008 Template Problem

Set is already a templated function. However for some reason, you want to cast "value" to a concrete type. Depending on what data_type is, there is no guarantee this cast will work, and there you have it -- the cast to const char* fails.

Code:

typedef struct
{
unsigned short group;
unsigned short element;
};

From what I gather, this is what value probably is, and there is no way you can cast a const char* to that struct.

ANSI C++ is a type-safe language, and since it has been standardized since 1998, all of these lax and/or illegal casts and code that VC 6.0 accepted is no longer acceptable in ANSI C++.

But the flaw in your code is that you're taking a templated function (Set) and assuming you can cast whatever value_type is to const char*, instead of making the call "flow through" without any casts done. That is the bottom line as far as what's wrong with the code.

You need to revisit what has been coded and recode it to follow proper ANSI C++ before Visual Studio accepts it.