473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

code compiles c++ 6.0, not in c++ .NET

I am having a very hard time getting my 6.0 C++ template code to
compile on C++ .NET.

The following is one example of code that compiles in 6.0 but not in
..NET. Any ideas why?

-----------------------------------------
#include <list>

template <class A> class Cursor : public std::list<A>::iterator
{
void PosAfterActual( std::list<A>::iterator it ) ;
} ;

------------------------------------------------

Error message is:

c:\SrcomNet\TestTclass2.h(8) : warning C4346:
'std::list<_Ty>::iterator' : dependent name is not a type
prefix with 'typename' to indicate a type
c:\SrcomNet\TestTclass2.h(9) : see reference to class template
instantiation 'Cursor<A>' being compiled
c:\SrcomNet\TestTclass2.h(8) : error C2061: syntax error : identifier
'iterator'
Any help is very appreciated.

-Steve Richter
Nov 16 '05 #1
14 1721
Steve Richter wrote:
I am having a very hard time getting my 6.0 C++ template code to
compile on C++ .NET.

The following is one example of code that compiles in 6.0 but not in
.NET. Any ideas why?
Because your code is not legal according to the C++ standard: a dependent
name is not a type unless prefixed with the typename keyword.

-----------------------------------------
#include <list>

template <class A> class Cursor : public std::list<A>::iterator
{
void PosAfterActual( std::list<A>::iterator it ) ;
void PosAfterActual( typename std::list<A>::iterator it );
} ;

------------------------------------------------

Error message is:

c:\SrcomNet\TestTclass2.h(8) : warning C4346:
'std::list<_Ty>::iterator' : dependent name is not a type
prefix with 'typename' to indicate a type
c:\SrcomNet\TestTclass2.h(9) : see reference to class template
instantiation 'Cursor<A>' being compiled
c:\SrcomNet\TestTclass2.h(8) : error C2061: syntax error : identifier
'iterator'
Any help is very appreciated.


-cd
Nov 16 '05 #2
"Carl Daniel [VC++ MVP]" <cp******@nospam.mvps.org> wrote in message news:<#4**************@TK2MSFTNGP11.phx.gbl>...
Steve Richter wrote:
I am having a very hard time getting my 6.0 C++ template code to
compile on C++ .NET.

The following is one example of code that compiles in 6.0 but not in
.NET. Any ideas why?


Because your code is not legal according to the C++ standard: a dependent
name is not a type unless prefixed with the typename keyword.

-----------------------------------------
#include <list>

template <class A> class Cursor : public std::list<A>::iterator
{
void PosAfterActual( std::list<A>::iterator it ) ;


void PosAfterActual( typename std::list<A>::iterator it );


What a language! Using it for 5 years and I still dont know what I am
doing.

This code, ok in 6.0, also did not compile in .NET:
HANDLE* pFile ;
vector<HANDLE> vec ;
vector<HANDLE>::iterator it ;
it = vec.begin( ) ;
pFile = it ;

it had to be changed to:
pFile = &(*it) ;

I dont like these changes. My code is windows specific, so portability
is a low priority. And the mods I have to make to my code appear to
make it less readable.

Does MS have a document that gets into the details of what was allowed
in VC++ 6.0 and is not in C++ .NET? I saw a migration guide on the
MSDN site, but it did not detail what I am running into.

thanks,

-Steve
Nov 16 '05 #3
Steve Richter wrote:
What a language! Using it for 5 years and I still dont know what I am
doing.
Yeah - 5 years after standardization, the people that wrote the standard are
still (actively!) discussing just exactly what the standard means. In
fairness to VC6 - the requirement for typename was added late in the
standardization process, after VC6 was already nearly shipping.

This code, ok in 6.0, also did not compile in .NET:
HANDLE* pFile ;
vector<HANDLE> vec ;
vector<HANDLE>::iterator it ;
it = vec.begin( ) ;
pFile = it ;

it had to be changed to:
pFile = &(*it) ;
This is due to library changes. Note that both implementations are
compliant with the standard - the standard simply doesn't say whether
vector<T>::iterator is a T* or not. In VC6, it is precisely a T*, in VC7
and above, it's a user defined class. Code like your pFile = it was never
guaranteed to work, whereas &*it is guaranteed to work.

I dont like these changes. My code is windows specific, so portability
is a low priority. And the mods I have to make to my code appear to
make it less readable.
In the case of &(*it), I'd have to agree, but then one could argue that you
shouldn't really be getting HANDLE*'s out of that vector anyway, but simply
using vector<HANDLE>::iterator. (And one could argue that that's nonesense
and you really need a HANDLE*, in which case you just have to pay for some
ugliness).

Does MS have a document that gets into the details of what was allowed
in VC++ 6.0 and is not in C++ .NET? I saw a migration guide on the
MSDN site, but it did not detail what I am running into.


I haven't seen anything that gets into this low level detail stuff. In
general, the changes in VC7 (and even more so, VC7.1) make the compiler much
closer to C++ standards conformance, so code that VC6 accepted that wasn't
quite standard conforming will frequently be kicked out by VC7{.1}.

-cd
Nov 16 '05 #4
"Steve Richter" <co********@yahoo.com> wrote:
[...]
This code, ok in 6.0, also did not compile in .NET:
HANDLE* pFile ;
vector<HANDLE> vec ;
vector<HANDLE>::iterator it ;
it = vec.begin( ) ;
pFile = it ;

it had to be changed to:
pFile = &(*it) ;
Right. Iterators aren't required to be plain
pointers, even though for 'std::vector<>' that
is possible.
I dont like these changes. My code is windows specific, so portability
is a low priority. And the mods I have to make to my code appear to
make it less readable.
Even on Windows there are different compilers.
And you have different versions of the same
compiler. If they all accept std C++, porting
among them will be easier. That's why I think
making your code std conforming is worthwile.

In your specific case above, you could ask
yourself why you're using 'HANDLE*' at all,
instead of just using 'HANDLE'. Usually, when
using a pointer you indicate that there might
be a value (ptr!=0) or there might not (ptr==0).
With a handle, that seems unnecessary, since
there already is a value for an invalid handle.
Also, the 'HANDLE*' in the above code will
always refer to an 'HANDLE' object. And that's
what references were invented for.
So why don't you write it this

HANDLE pFile = *it ;

way? Unless there's a good reason for using a
pointer I would always prefer references.
Does MS have a document that gets into the details of what was allowed
in VC++ 6.0 and is not in C++ .NET? I saw a migration guide on the
MSDN site, but it did not detail what I am running into.
Basically, a lot of code that isn't standard
conforming and used to compile with VC6 won't
compile anymore. I'm not aware of a document
which lists all the differences.
(Note that the above cannot be blamed on VC6.
You were simply taking advantage of an
implementation detail of your std library.)
thanks,
HTH,
-Steve


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #5
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
[...]
I dont like these changes. My code is windows specific, so portability
is a low priority. And the mods I have to make to my code appear to


You are using a language called C++ and Microsoft delivers a C++ compiler.
The code you wrote and VC6.0 compiled wasn't complaint with the C++
Standard. If Microsoft were to continue to support such code, it really
would be a new language say VC++6. Note that for a few easy things (e.g.,
"for" variable scoping), the compiler allows you to tweak C++ slightly.

Dan
Nov 16 '05 #6
"Hendrik Schober" <Sp******@gmx.de> wrote in message news:<O$**************@tk2msftngp13.phx.gbl>...
"Steve Richter" <co********@yahoo.com> wrote:
[...]
This code, ok in 6.0, also did not compile in .NET:
HANDLE* pFile ;
vector<HANDLE> vec ;
vector<HANDLE>::iterator it ;
it = vec.begin( ) ;
pFile = it ;

it had to be changed to:
pFile = &(*it) ;


Right. Iterators aren't required to be plain
pointers, even though for 'std::vector<>' that
is possible.

In your specific case above, you could ask
yourself why you're using 'HANDLE*' at all,
instead of just using 'HANDLE'. Usually, when
using a pointer you indicate that there might
be a value (ptr!=0) or there might not (ptr==0).
With a handle, that seems unnecessary, since
there already is a value for an invalid handle.
Also, the 'HANDLE*' in the above code will
always refer to an 'HANDLE' object. And that's
what references were invented for.
So why don't you write it this

HANDLE pFile = *it ;


the MsgWaitForMultipleObjects( ... ) api calls for a pointer to an
array of handles to be waited for. I wrapped that api with a version
that accepts a vector of handles:

namespace steve {
DWORD MsgWaitForMultipleObjects( const std::vector<HANDLE>& handles,
.... )
{
DWORD dwRc ;
const HANDLE* pHandles ;
int nHandleCx = handles.size( ) ;
pHandles = handles.Begin( ) ;
dwRc = ::MsgWaitForMultipleObjects( nHandleCx, (HANDLE*)pHandles,
.... ) ;
return dwRc ;
}
} ; // end namespace steve

That made it a little easier to call that api. Then I really went
wild and used vector<HANDLE> as a base class to a class that makes it
easier to build the vector of handles:
class vector_handles : public std::vector<HANDLE>
{
vector_handles( HANDLE h1 ) ;
vector_handles( HANDLE h1, HANDLE h2 ) ; // build vector with 2
handles.
vector_handles& operator<<( HANDLE hIn )
{ push_back( hIn ) ; return *this ; }
...
} ;

this class lets me call my version of MsgWait... like so:
steve::MsgWaitForMultipleObjects( vector_handles( hMutex, hThread
), ... ) ;
Does MS have a document that gets into the details of what was allowed
in VC++ 6.0 and is not in C++ .NET? I saw a migration guide on the
MSDN site, but it did not detail what I am running into.


Basically, a lot of code that isn't standard
conforming and used to compile with VC6 won't
compile anymore. I'm not aware of a document
which lists all the differences.
(Note that the above cannot be blamed on VC6.
You were simply taking advantage of an
implementation detail of your std library.)


this NG is very good. thanks a lot.

-Steve
Nov 16 '05 #7
"Steve Richter" <co********@yahoo.com> wrote:
[...]
So why don't you write it this

HANDLE pFile = *it ;
the MsgWaitForMultipleObjects( ... ) api calls for a pointer to an
array of handles to be waited for. [...]


I see. Then you have the choice between
'&*v.begin()' or '&v[0]', which seem
equally bad at first. However, you will
get used to it.
-Steve


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #8
"Dan Smith" <J_************@HoTMaiL.com> wrote in message news:<O2**************@TK2MSFTNGP11.phx.gbl>...
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
[...]
I dont like these changes. My code is windows specific, so portability
is a low priority. And the mods I have to make to my code appear to


You are using a language called C++ and Microsoft delivers a C++ compiler.
The code you wrote and VC6.0 compiled wasn't complaint with the C++
Standard. If Microsoft were to continue to support such code, it really
would be a new language say VC++6. Note that for a few easy things (e.g.,
"for" variable scoping), the compiler allows you to tweak C++ slightly.


Hi Dan,

In practice, dont the standards stifle the development of the
language? When was a feature last added to C++?

Here are some additions I would like to see made to the language:
- #define scopable to a namespace
- ambiguous overload or base class - I would like to be able to tell
the compiler that a function or base class is prefered over
another.
- too much typing!
string* pName = new string ; // why must I type "string"
twice?
- C++ should fit in the managed world without having to be dumbed
down.
- built in reference counting
- pName = gc_new string ; // pName will be auto garbage
collected
- pName2 = pName ; // somehow incs a reference count.

Anyway. I dont intend my code to run on any platform other than
windows. I dont see how rigid standards benefit me at all.

-Steve
Nov 16 '05 #9
Steve Richter wrote:
Hi Dan,

In practice, dont the standards stifle the development of the
language? When was a feature last added to C++?
1998. Only a few months ago, was there finally a (one, uno) compiler
released that claims to actually implement the entire C++ standard.

Here are some additions I would like to see made to the language:
- #define scopable to a namespace
This is a common request.
- ambiguous overload or base class - I would like to be able to tell
the compiler that a function or base class is prefered over
another.
- too much typing!
string* pName = new string ; // why must I type "string"
twice?
You'll likely see something to address this (imagine how bad it is if the
type is significantly more complex than 'string') in the next rev of the C++
standard. See, for example,
http://anubis.dkuug.dk/jtc1/sc22/wg2...2003/n1527.pdf, which
discusses one proposal to address this type of concern.
- C++ should fit in the managed world without having to be dumbed
down.
- built in reference counting
- pName = gc_new string ; // pName will be auto garbage
collected
- pName2 = pName ; // somehow incs a reference count.


Note that the managed world does not use reference counting, but Stay Tuned.
The desire for C++ to play well in the managed world is well known within
the VC team and in the industry at large (see e.g.
http://www.ecma-international.org/news/ecma-TG5-PR.htm). Expect to see
something in the future...

-cd
Nov 16 '05 #10
"Steve Richter" <co********@yahoo.com> wrote:
[...]
Hi Dan,

In practice, dont the standards stifle the development of the
language? When was a feature last added to C++?
This year with TR1. The features (AFAIK all
library enhancements) are supposed to become
part of the next standard (which cannot be
released before 2008).
Here are some additions I would like to see made to the language:
- #define scopable to a namespace
'inline', 'const'
[...]
- too much typing!
string* pName = new string ; // why must I type "string"
twice?
What about this
Base* p = new Derived;
then?
- C++ should fit in the managed world without having to be dumbed
down.
MC++ was created by one corporation. Shouldn't
it fit everybody's world then?
- built in reference counting
I wouldn't want to have the problems of
this. If you can live with them -- fine.
C++ allows us to have both and even more:
http://www.cuj.com/documents/s=7994/...r/alexandr.htm
- pName = gc_new string ; // pName will be auto garbage
collected
- pName2 = pName ; // somehow incs a reference count.

That's spelled
boost::shared_ptr<string> pName( new string );
in C++.
(BTW, AFAIK, Boost's pointers are part of TR1
and should thus become members of the namespace
'std'.)
Anyway. I dont intend my code to run on any platform other than
windows. I dont see how rigid standards benefit me at all.
Windows already is a whole bunch of platforms.
And while you don't intend to port to anything
else, what about your boss? And what in five
years?
We have ported quite some code that never was
intended to get ported. The closer the code was
to the C++ std, the smaller the effort.
-Steve


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #11
I'm not trying to claim (right now) that you benefit from Standard C++ (you
do, but that's a different discussion).

Rather, the language that VC6.0 compiled really wasn't C++, let's call it
instead VCPP6. Just like C++ has a lot in common with C, VCPP6 has at lot
in common with C++, but as your code illustrates they aren't the same
language. Since I think there is only one compiler that is fully Standard
C++ compliant (EDG), the same thing can be said for VC7.0 and VC7.1. The
difference is that VCPP71 is a lot closer to Standard C++ than VCPP6.

So, just how many different C++-like languages should Microsoft support?
And what should that support entail? Should VCPP6 have managed extensions
too? It's hard enough to just implement Standard C++; I'm sure that
supportting VCPP6 in Visual Studio 2003 would be a lot of work.

Dan

"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
"Dan Smith" <J_************@HoTMaiL.com> wrote in message

news:<O2**************@TK2MSFTNGP11.phx.gbl>...
"Steve Richter" <co********@yahoo.com> wrote in message
news:c0**************************@posting.google.c om...
[...]
I dont like these changes. My code is windows specific, so portability
is a low priority. And the mods I have to make to my code appear to


You are using a language called C++ and Microsoft delivers a C++ compiler. The code you wrote and VC6.0 compiled wasn't complaint with the C++
Standard. If Microsoft were to continue to support such code, it really
would be a new language say VC++6. Note that for a few easy things (e.g., "for" variable scoping), the compiler allows you to tweak C++ slightly.


Hi Dan,

In practice, dont the standards stifle the development of the
language? When was a feature last added to C++?

Here are some additions I would like to see made to the language:
- #define scopable to a namespace
- ambiguous overload or base class - I would like to be able to tell
the compiler that a function or base class is prefered over
another.
- too much typing!
string* pName = new string ; // why must I type "string"
twice?
- C++ should fit in the managed world without having to be dumbed
down.
- built in reference counting
- pName = gc_new string ; // pName will be auto garbage
collected
- pName2 = pName ; // somehow incs a reference count.

Anyway. I dont intend my code to run on any platform other than
windows. I dont see how rigid standards benefit me at all.

-Steve

Nov 16 '05 #12
"Dan Smith" <J_************@HoTMaiL.com> wrote in message news:<e5**************@TK2MSFTNGP12.phx.gbl>...
I'm not trying to claim (right now) that you benefit from Standard C++ (you
do, but that's a different discussion).

Rather, the language that VC6.0 compiled really wasn't C++, let's call it
instead VCPP6. Just like C++ has a lot in common with C, VCPP6 has at lot
in common with C++, but as your code illustrates they aren't the same
language. Since I think there is only one compiler that is fully Standard
C++ compliant (EDG), the same thing can be said for VC7.0 and VC7.1. The
difference is that VCPP71 is a lot closer to Standard C++ than VCPP6.

So, just how many different C++-like languages should Microsoft support?
And what should that support entail? Should VCPP6 have managed extensions
too? It's hard enough to just implement Standard C++; I'm sure that
supportting VCPP6 in Visual Studio 2003 would be a lot of work.

Dan


Yeah I guess so. No problem. I really appreciate the feedback from
all and have ordered the Alexandrescu book:

http://www.amazon.com/exec/obidos/tg...79277?v=glance

-Steve
Nov 16 '05 #13
Steve,

Yes, I have been using C++ for 9 years now.
Basically the newer VC 7.1 compiler follows the C++
standard much better. This would be the same if you where
gnu gcc 3+ versions or other compilers.

Unfortunately Kai c++ is no longer or was taken over by
Intel so there is no more Solaris support there for the
newest version.
Kai C++ used to be the best compiler for following the
standard and giving you great error messages.

Lars Schouw
Nov 16 '05 #14
an*******@discussions.microsoft.com <an*******@discussions.microsoft.com> wrote:
[...]
Kai C++ used to be the best compiler for following the
standard and giving you great error messages.
It seems as if Comeau has got this reputation
now: www.comeaucomputing.com.
Lars Schouw


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers org

"And why should I know better by now/When I'm old enough not to?"
Beth Orton
Nov 16 '05 #15

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

Similar topics

0
by: RichG | last post by:
I have a problem where DB2 is returning error 'DIA9999E An internal error occurred. Report the following error code : "error code -32"'. This is happening on DB2 for Windows, v7.2.9 when compiling...
13
by: AFKAFB | last post by:
Hi Sometimes when i edit previously saved VBA code e.g. To update field names etc the revised code does not work. Even if i copy and paste in a previous version it does not work. The only...
5
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
26
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
8
by: mastermagrath | last post by:
Hi, I'm about half way through Bruce Eckels thinking in C++ Vol 1. He gives a very short example of how compiler function name decoration helps remove subtle bugs by type-safe linkage. However,...
15
by: Neo | last post by:
Hello All, I found that ASP.net website only accepts code withing site directory. This creates big hurdle in shairng code. How to share code between two websites, like the way share between two...
13
by: jc | last post by:
I have written a parser using bison and flex to read ASAP2 file for CAN communications. entire development was done in an unix environment and now the code is ready to be integrated to an existing...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
10
by: Keith Halligan | last post by:
I'm switching from the HP-UX compiler aCC 5.55 to aCC 6.13 and I get the following error: "templateptr.h", line 20: error #2289: no instance of constructor "defclass::base::base" matches the...
4
by: Michael Starberg | last post by:
- If it compiles, it works. - If it compiles, it's correct. - If it runs, it doesn't have any bugs. - If it doesn't have any immediately obvious bugs, it's perfect. - If a bug doesn't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.