typedef的问题 [英] A problem with typedef

查看:76
本文介绍了typedef的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

#include< iostream>

使用命名空间std;


typedef double DOUBLE ;


级屏幕

{

公开:

typedef int DOUBLE;

DOUBLE OK;


};


int main()

{

返回0;

}


mingw(使用gcc 3.4.2)给出错误:

从`typedef double

改变'DOUBLE'的含义但是vc7给​​出了OK。哪一个是对的?

the code is as follows:
#include <iostream>
using namespace std;

typedef double DOUBLE;

class Screen
{
public:
typedef int DOUBLE;
DOUBLE OK;

};

int main()
{
return 0;
}

the mingw(with the gcc 3.4.2) give an error:
changes meaning of `DOUBLE'' from `typedef double
but the vc7 gives OK. so which one is right?

推荐答案

2006年12月22日06:13:40 -0800," mi **** *****@gmail.com"

< mi ********* @ gmail.comwrote in comp.lang.c ++:
On 22 Dec 2006 06:13:40 -0800, "mi*********@gmail.com"
<mi*********@gmail.comwrote in comp.lang.c++:

代码如下:

#include< iostream>

使用命名空间std;


typedef double DOUBLE;
the code is as follows:
#include <iostream>
using namespace std;

typedef double DOUBLE;



为什么?

Why?


class Screen

{

public:

typedef int DOUBLE;
class Screen
{
public:
typedef int DOUBLE;



为什么?

Why?


DOUBLE OK;


} ;


int main()

{

返回0;

}


mingw(使用gcc 3.4.2)给出错误:

从`typedef double

改变'DOUBLE'的意思但是vc7给出了OK。哪一个是对的?
DOUBLE OK;

};

int main()
{
return 0;
}

the mingw(with the gcc 3.4.2) give an error:
changes meaning of `DOUBLE'' from `typedef double
but the vc7 gives OK. so which one is right?



你的意思是给出错误?允许编译器发出

它想要的任何类型的消息,只要它发出标准所要求的诊断

。它是否产生可执行文件?如果确实如此,

它符合这方面的标准。安静地没有

的要求。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答for

comp.lang.c http://c-faq.com /

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~ a ... FAQ-acllc.html

What do you mean by "give an error"? A compiler is allowed to issue
any sort of messages it wants to, as long as it issues diagnostics
required by the standard. Does it produce an executable? If it does,
it is conforming to the standard in this respect. There is no
requirement that it do so quietly.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


我认为VC编译器应该给出错误,但可能不会。因为你

在不同的范围内有typedef DOUBLE,一个在全局,另一个在

类。

mi ********* @ gmail.com 写道:
I think VC compiler should give an error, but it may not. Because you
have typedef DOUBLE in defferent scope, one in global and other one in
class.

mi*********@gmail.com wrote:

代码如下:

#include< iostream>

使用命名空间std;


typedef double DOUBLE;


级屏幕

{

公开:

typedef int DOUBLE;

DOUBLE OK;


};


int main()

{

返回0;

}


mingw(使用gcc 3.4.2)给出错误:

更改含义来自`typedef double

的'DOUBLE'',但vc7给出了OK。哪一个是对的?
the code is as follows:
#include <iostream>
using namespace std;

typedef double DOUBLE;

class Screen
{
public:
typedef int DOUBLE;
DOUBLE OK;

};

int main()
{
return 0;
}

the mingw(with the gcc 3.4.2) give an error:
changes meaning of `DOUBLE'' from `typedef double
but the vc7 gives OK. so which one is right?


没有原因。我刚刚阅读了C ++ Primer 4th。在第448页中,有一些关于全局范围和类范围内的typedef的内容。我想看看这本书中流行的示例代码编译器。


BTW:如果类中的typedef写在DOUBLE OK后面,两个

编译器都会给出OK。

没有编译错误。但是如果在DOUBLE

OK之前写入了typedef,则mingw会出现编译错误。


等等在此之前或之前,英特尔CPP编译器,VC7和Comeau

都给予OK!

" Jack Klein D'μà£o

" ;
there is no why. I just read the C++ Primer 4th. In Page 448 ,there
are something about the typedef in global scope and in class scope.I
just have a try about the book''s example code in the popular compilers.

BTW: if the typedef in class is written behind the "DOUBLE OK", both
compilers give OK.
there is no compile error.But if the typedef is written before "DOUBLE
OK", the mingw give a compile error.

And whatever behind or before , the Intel CPP compiler , VC7 and Comeau
all give OK!
"Jack Klein D′μà£o
"

2006年12月22日06:13:40 -0800,mi ********* @ gmail.com

< mi ********* @ gmail.comwrote in comp.lang.c ++:
On 22 Dec 2006 06:13:40 -0800, "mi*********@gmail.com"
<mi*********@gmail.comwrote in comp.lang.c++:

代码如下:

#include< iostream>

使用命名空间std;


typedef double DOUBLE;
the code is as follows:
#include <iostream>
using namespace std;

typedef double DOUBLE;



为什么?


Why?


>
>

class Screen

{

public:

typedef int DOUBLE;
class Screen
{
public:
typedef int DOUBLE;



为什么?


Why?


DOUBLE OK;


} ;


int main()

{

返回0;

}


mingw(使用gcc 3.4.2)给出错误:

从`typedef double

改变'DOUBLE'的意思但是vc7给出了OK。哪一个是对的?
DOUBLE OK;

};

int main()
{
return 0;
}

the mingw(with the gcc 3.4.2) give an error:
changes meaning of `DOUBLE'' from `typedef double
but the vc7 gives OK. so which one is right?



你的意思是给出错误?允许编译器发出

它想要的任何类型的消息,只要它发出标准所要求的诊断

。它是否产生可执行文件?如果确实如此,

它符合这方面的标准。安静地没有

的要求。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答for

comp.lang.c http://c-faq.com /

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~ a ... FAQ-acllc.html


这篇关于typedef的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆