关于类型转换 [英] regarding typecasting

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

问题描述




我是c ++编程语言的新手。我写了一个小程序,

然后我传递char字符串,然后找出长度。


find_len(char * str);是函数的proto类型。


我做了类型转换为char赋予新名称,


typedef signed char sint;


然后我替换了函数调用


find_len(sint * str);


当我编译,我收到错误说,无效转换

从`sint *''到'char *''


i我无法理解,什么问题是什么?请帮助我

知道,为什么会出现这个问题。


感谢你在这方面的帮助。


谢谢,

Vikas。

解决方案

请用typdef替换类型转换。


vikas


6月5日,6:09 * pm,venkat< venkatavi ... @ gmail.comwrote:





我是c ++编程语言的新手。我写了一个小程序,

然后我传递char字符串,然后找出长度。


find_len(char * str);是函数的proto类型。


我做了类型转换为char赋予新名称,


typedef signed char sint;


然后我替换了函数调用


find_len(sint * str);


当我编译,我收到错误说,无效转换

从`sint *''到'char *''


i我无法理解,什么问题是什么? *请帮助我

知道,为什么会出现这个问题。


感谢你在这方面的帮助。


谢谢,

Vikas。


venkat写道:





我是c ++编程语言的新手。我写了一个小程序,

然后我传递char字符串,然后找出长度。


find_len(char * str);是函数的proto类型。


我做了类型转换为char赋予新名称,


typedef signed char sint;



在这里,你给char更新了一个新的名字。即使char在您的实现上签名

,它仍然是一个不同类型。


然后我替换了函数调用与


find_len(sint * str);


当我编译时,我收到错误说,无效转换

从`sint *''到'char *''


i我无法理解,问题是什么?请帮助我

知道,为什么会出现这个问题。



没有从signed char *到char *的隐式转换。因此,

功能不匹配。


最佳


Kai-Uwe Bux


6月5日,6:15 * pm,Kai-Uwe Bux< jkherci ... @ gmx.netwrote:


venkat写道:




我是c ++编程语言的新手。我写了一个小程序,

然后我传递char字符串,然后找出长度。


find_len(char * str);是该函数的proto类型。


我做了类型转换以给char添加新名称,


typedef signed char sint;



在这里,你给char更新了一个新的名字。即使char在您的实现上签名

,它仍然是一个不同的类型。


然后我用$ b $替换函数调用b


find_len(sint * str);


当我编译时,我收到错误说,无效转换

从`sint *''到`char *''


i无法理解,问题是什么? *请帮助我

知道,为什么会出现这个问题。



没有从signed char *到char *的隐式转换。因此,

函数不匹配。


>>>这是否意味着我在c ++中使用char和signed char是不同的,而C语言则不然。


>>>我是否必须拥有typedef char sint; ,使代码工作。


Best


Kai-Uwe Bux

Hi,

I am new to c++ programming language. I have written small program ,
where i pass the char string then , i find out length.

find_len( char *str); is the proto type for the function.

I did type casting to give new name to char ,

typedef signed char sint;

Then i replaced the function call with

find_len(sint *str);

when i compiled, i am getting the error saying, invalid conversion
from `sint*'' to `char*''

i am not able to understand, what was the problem?. Please help me
out in knowing, why this problem is happening.

Appreciate your help in this regard.

Thanks,
Vikas.

解决方案

Please replace typecast with typdef.

vikas

On Jun 5, 6:09*pm, venkat <venkatavi...@gmail.comwrote:

Hi,

I am new to c++ programming language. I have written small program ,
where i pass the char string then , i find out length.

find_len( char *str); is the proto type for the function.

I did type casting to give new name to char ,

typedef signed char sint;

Then i replaced the function call with

find_len(sint *str);

when i compiled, i am getting the error saying, invalid conversion
from `sint*'' to `char*''

i am not able to understand, what was the problem?. *Please help me
out in knowing, why this problem is happening.

Appreciate your help in this regard.

Thanks,
Vikas.


venkat wrote:

Hi,

I am new to c++ programming language. I have written small program ,
where i pass the char string then , i find out length.

find_len( char *str); is the proto type for the function.

I did type casting to give new name to char ,

typedef signed char sint;

Here you give a new name to signed char not to char. Even if char is signed
on your implementation, it is still a different type.

Then i replaced the function call with

find_len(sint *str);

when i compiled, i am getting the error saying, invalid conversion
from `sint*'' to `char*''

i am not able to understand, what was the problem?. Please help me
out in knowing, why this problem is happening.

There is no implicit conversion from signed char * to char *. Therefore, the
function does not match.

Best

Kai-Uwe Bux


On Jun 5, 6:15*pm, Kai-Uwe Bux <jkherci...@gmx.netwrote:

venkat wrote:

Hi,

I am new to c++ programming language. I have written small program ,
where i pass the char string then , i find out length.

find_len( char *str); is the proto type for the function.

I did type casting to give new name to char ,

typedef signed char sint;


Here you give a new name to signed char not to char. Even if char is signed
on your implementation, it is still a different type.

Then i replaced the function call with

find_len(sint *str);

when i compiled, i am getting the error saying, invalid conversion
from `sint*'' to `char*''

i am not able to understand, what was the problem?. *Please help me
out in knowing, why this problem is happening.


There is no implicit conversion from signed char * to char *. Therefore, the
function does not match.

>>>Does that means, i have char and signed char are different in c++, which is not the case in C language.

>>>Do i have to have a "typedef char sint;" , for making the code to work.

Best

Kai-Uwe Bux


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

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