confused g ++ err msg'不赞成从字符串常量转换为char *' [英] confused g++ err msg 'deprecated conversion from string constantto char*'

查看:109
本文介绍了confused g ++ err msg'不赞成从字符串常量转换为char *'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我的编译器(g ++ 2.95.4)的错误信息告诉我:

robot.cpp:在方法`Robot :: Robot()''中:

robot.cpp:19:警告:不推荐将字符串常量转换为`char *''

在我的文件''robot.cpp'的第19行中,我声明了类的构造函数

机器人如:


18

19机器人::机器人(){

20

21 cout<< 欢迎来到Robot'的ctor! <<结束;

22

23 //做一些事情......

24

25} //结束ctor

26


在第19行中没有''字符串''或''char * s'',或者我是否会失明?

我是否会在不知情的情况下拨打一个深藏的lib或者其他东西?

好​​的,这是一个警告所以它似乎不是很seroius。

那是什么我thougt但我错了!


我可以编译编程,但它不起作用! :-(


神秘的是,当我启动调试器时,我到达第19行但

从不排第20行。


感谢您阅读本文


Gregor(gp**@gmx.de)

解决方案

" G.Peter"< gp ** @ gmx.de>写道......

我的编译器有一个搞笑错误信息(g ++ 2.95.4)告诉我:

robot.cpp:方法`Robot :: Robot()'':
robot.cpp:19:警告:不推荐使用从字符串常量转换为`char
*''

在我的文件''robot.cpp'的第19行中,我声明了类
机器人的构造函数:
18
19机器人::机器人(){
20
21 cout<<欢迎来到机器人's ctor!"<< endl;
22
23 //做一些事......
24
25} //结束ctor
26

第19行都没有''字符串''或''char * s'',或我瞎了吗?


类定义是什么样的?

我是否在不知情的情况下调用深藏的lib或其他东西?


编译器通常会错误计算行号。你确定这是精确的行吗?

好​​吧,这是一个警告,所以它似乎不是很seroius。
这就是我的意思但是我错了!

我可以编译编程,但它不起作用! :-(


不幸的是,基于您决定分享的代码数量,没有任何建议可以建议。

神秘事情是,当我启动调试器时,我到达第19行,但
从不第20行。




我不知道该告诉你什么,除了, ;升级您的编译器。


Victor





Victor Bazarov写道:

类定义是什么样的?
http://www.rob.uni-luebeck.de/~peter..._Robot/robot.h

编译器通常会错误计算行号。你确定它是精确的行吗?
我该怎么办?

但我不是在处理叮咬根本不知道(据我所知:-)


不幸的是,根据你决定分享的代码数量,没有任何建议。
F或答案我给你我所有的代码

请参阅完整的代码

http://www.rob.uni-luebeck.de/~peter/Class_Robot


我不知道该告诉你什么,除了升级你的编译器。



我试过了,但这有很多其他副作用,这是

a不同的新闻组......


" G.彼得" < GP ** @ gmx.de>写道:

Victor Bazarov写道:

类定义是什么样的? http://www.rob.uni-luebeck .de /〜彼得...... _ Robot / robot.h




谢谢。不幸的是,没有帮助。

编译器经常错误地计算行号。你确定它是精确的线吗?


我该怎么办?




您可以使用某种编译器 - 要输出的特定宏

行号(__LINE__应该扩展到那个)。你可以

把#error放到那一行之后,看看它是否确实来了......

但我根本没有处理蜇(据我所知) :-)


警告经常出现在:


char * str =" abc";


" abc"类型为const char [],''str''是char *。初始化

指向char的指针,指向(或数组)const char是允许的,但是不建议使用


不幸的是,根据你决定分享的代码数量,没有什么可以建议的。


我给你的答案我给你的所有代码
请参阅

的完整代码 http: //www.rob.uni-luebeck.de/~peter/Class_Robot




对不起,这不是完整的代码。
< blockquote class =post_quotes>

我不知道该告诉你什么,除了升级你的编译器。


我试过了,但是有一个很多其他副作用,这是一个不同的新闻组中的主题...




嗯,这取决于你。


Victor


Hi there,

I''ve a ''funny'' error message of my compiler (g++ 2.95.4) that tells me:

robot.cpp: In method `Robot::Robot()'':
robot.cpp:19: warning: deprecated conversion from string constant to `char *''
In Line 19 of my file ''robot.cpp'' I declare the constructor of class
robot like:

18
19 Robot::Robot(){
20
21 cout << "welcome to Robot''s ctor!" << endl;
22
23 //do some things ...
24
25 } // end ctor
26

In line 19 are no ''strings'' or ''char*s'', or am I blind?
Do I call a deep hidden lib or something without knowing it?
OK, it is a warning so it seems not to be very seroius.
That was what I thougt but I was wrong!

I can compile the prog, but it does not work! :-(

The mysterious thing is, when I start the debugger I reach line 19 but
never line 20.

Thanks for reading this

Gregor (gp**@gmx.de)

解决方案

"G. Peter" <gp**@gmx.de> wrote...

I''ve a ''funny'' error message of my compiler (g++ 2.95.4) that tells me:

robot.cpp: In method `Robot::Robot()'':
robot.cpp:19: warning: deprecated conversion from string constant to `char *''

In Line 19 of my file ''robot.cpp'' I declare the constructor of class
robot like:

18
19 Robot::Robot(){
20
21 cout << "welcome to Robot''s ctor!" << endl;
22
23 //do some things ...
24
25 } // end ctor
26

In line 19 are no ''strings'' or ''char*s'', or am I blind?
What''s the class definition look like?
Do I call a deep hidden lib or something without knowing it?
Compilers often miscalculate the line number. Are you sure it''s
that precise line?
OK, it is a warning so it seems not to be very seroius.
That was what I thougt but I was wrong!

I can compile the prog, but it does not work! :-(
Unfortunately, nothing can be advised based on the amount of code
you decided to share.
The mysterious thing is, when I start the debugger I reach line 19 but
never line 20.



I don''t know what to tell you except, "Upgrade your compiler".

Victor




Victor Bazarov wrote:

What''s the class definition look like? http://www.rob.uni-luebeck.de/~peter..._Robot/robot.h

Compilers often miscalculate the line number. Are you sure it''s
that precise line? How can I?
But I am not dealing with stings at all (as far as I know :-)

Unfortunately, nothing can be advised based on the amount of code
you decided to share. For an answer I give you all the code I have
See the complete code at

http://www.rob.uni-luebeck.de/~peter/Class_Robot

I don''t know what to tell you except, "Upgrade your compiler".


I tried that, but that has a lot of other side effects which is topic in
a different news group ...


"G. Peter" <gp**@gmx.de> wrote...

Victor Bazarov wrote:

What''s the class definition look like? http://www.rob.uni-luebeck.de/~peter..._Robot/robot.h



Thanks. Doesn''t help, unfortunately.

Compilers often miscalculate the line number. Are you sure it''s
that precise line?


How can I?



You could use some kind of compiler-specific macro to output
the line number (__LINE__ should expand to that). You could
put #error after that line and see if it does come to it...
But I am not dealing with stings at all (as far as I know :-)
The warning often appears at this:

char *str = "abc";

"abc" has type const char[], and ''str'' is a char*. Initialisation
of a pointer to char with a pointer to (or array of) const char is
allowed but is not advised.

Unfortunately, nothing can be advised based on the amount of code
you decided to share.


For an answer I give you all the code I have
See the complete code at

http://www.rob.uni-luebeck.de/~peter/Class_Robot



Sorry, this is not the complete code.

I don''t know what to tell you except, "Upgrade your compiler".


I tried that, but that has a lot of other side effects which is topic in
a different news group ...



Well, it''s up to you then.

Victor


这篇关于confused g ++ err msg'不赞成从字符串常量转换为char *'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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