代码编译c ++ 6.0,而不是c ++ .NET [英] code compiles c++ 6.0, not in c++ .NET
问题描述
我很难将我的6.0 C ++模板代码转换为
在C ++ .NET上编译。
以下是代码的一个示例编译在6.0但不在
..NET中。有什么想法吗?
---------------------------------- -------
#include< list>
模板< class A> class Cursor:public std :: list< A> :: iterator
{
void PosAfterActual(std :: list< A> :: iterator it);
};
------------------------------- -----------------
错误信息是:
c:\SrcomNet \\ \\ TestTclass2.h(8):警告C4346:
''std :: list< _Ty> :: iterator'':依赖名称不是类型
前缀'' 类型名称 '' 来指示类型
C:\SrcomNet\TestTclass2.h(9):见参考类模板
实例 '' 光标< a取代; ''正在编译
c:\SrcomNet \ TestTclass2.h(8):错误C2061:语法错误:标识符
''iterator''
非常感谢任何帮助。
-Steve Richter
Steve Richter写道:< blockquote class =post_quotes>我很难将我的6.0 C ++模板代码转换为
在C ++ .NET上编译。
以下是在6.0中编译而不在.NET中编译的代码示例。有什么想法吗?
因为您的代码根据C ++标准是不合法的:依赖
名称不是类型,除非前缀为typename关键字。
-----------------------------------------
#包括< list>
模板< A类> class Cursor:public std :: list< A> :: iterator
{void PosAfterActual(std :: list< A> :: iterator it);
void PosAfterActual(typename std :: list< A> :: iterator it);
};
--- ---------------------------------------------
<错误信息是:
c:\SrcomNet \ TestTclass2.h(8):警告C4346:
''std :: list< _Ty> :: iterator'' :依赖名称不是类型
前缀,带有''typename''来表示类型
c:\SrcomNet \ TestTclass2.h(9):参见类模板
实例化''光标< A>''正在编译
c:\SrcomNet \ TestTclass2.h(8):错误C2061:语法错误:标识符
''iterator''
非常感谢任何帮助。
-cd
" Carl Daniel [VC ++ MVP]" ; < CP ****** @ nospam.mvps.org>在消息新闻中写道:<#4 ************** @ TK2MSFTNGP11.phx.gbl> ...Steve Richter写道:我很难将我的6.0 C ++模板代码编译成在C ++ .NET上编译。
以下是在6.0中编译但不在
.NET。有什么想法?
因为你的代码根据C ++标准是不合法的:除非前缀为typename关键字,否则依赖名称不是类型。
-------------------------------------- ---
#include< list>
模板< class A>类光标:公共的std ::列表< a取代;:迭代
{
空隙PosAfterActual(标准::列表< a取代;:迭代它);
void PosAfterActual(typename std :: list< A> :: iterator it);
用什么语言!使用它5年,我仍然不知道我在做什么
做什么。
这个代码,6.0中的确定,也没有在.NET中编译:
HANDLE * pFile;
vector< HANDLE> vec;
vector< HANDLE> :: iterator it;
it = vec.begin();
pFile = it;
它必须改为:
pFile =&(* it);
我不喜欢这些变化。我的代码是特定于Windows的,所以便携性
是低优先级。我必须对我的代码进行的修改似乎是
使其可读性降低。
MS是否有一份文档可以了解详细信息允许在VC ++ 6.0中使用
并且不在C ++ .NET中?我在
MSDN网站上看到了迁移指南,但它没有详细说明我遇到的情况。
谢谢,
>
-Steve
Steve Richter写道:多么语言!使用它5年,我仍然不知道我在做什么。
是的 - 标准化后5年,编写标准的人仍然(积极地!)讨论标准的含义。在
对VC6的公平性 - 在VC6已经快要发货之后,在
标准化过程的后期添加了typename的要求。
此代码,确定在6.0中,也没有在.NET中编译:
HANDLE * pFile;
vector< HANDLE> vec;
vector< HANDLE> :: iterator it;
it = vec.begin();
pFile = it;
它必须改为:
pFile =&(* it);
这是由于图书馆的变化。请注意,这两种实现方式都符合标准 - 标准只是没有说明是否
向量< T> :: iterator是否为T *。在VC6中,它恰好是T *,在VC7
及以上,它是用户定义的类。代码就像你的pFile =它永远不会
保证工作,而& *保证可以工作。
我不喜欢这些变化。我的代码是特定于Windows的,因此可移植性优先级较低。我必须对我的代码进行的修改似乎使它的可读性降低。
在&(* it)的情况下,我不得不同意,但是有人可能会争辩说你不应该
不应该无论如何,真的要从那个矢量中得到HANDLE *,但是使用vector< HANDLE> :: iterator只需要使用
。 (而且有人可能会说这是'无所事事'
而你真的需要一个HANDLE *,在这种情况下你只需支付一些
gggg)。 />
MS是否有一个文档可以深入了解VC ++ 6.0中允许的内容的细节,而不是在C ++ .NET中?我在
MSDN网站上看到了一个迁移指南,但它没有详细说明我遇到的情况。
我还没有看到任何东西进入这个低级细节的东西。在
一般情况下,VC7中的变化(甚至更多,VC7.1)使编译器更接近C ++标准一致性,因此VC6接受的代码不是'$
相当标准的符合性将经常被VC7 {.1}踢出。
-cd
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
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
"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
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
这篇关于代码编译c ++ 6.0,而不是c ++ .NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!