是否有一种方法可以通过原型制作更改类型的INT来键入char
Is there a way to change type int to type char by prototyping?
我正在制作一个项目。这是单独文件中的函数声明。
void PrintLines(int characterValue, int characterCount, int lineCount)
当我在主文件中原型时,我会使用:
void PrintLines(char characterValue, int characterCount, int lineCount);
这不会编译。我可以使用任何方法在不更改第一个INT类型的情况下将其输入主要方法(在其他文件中?
中)我认为我必须输入演员。只需要弄清楚如何。
基本上,代码必须为
void PrintLines(int characterValue, int characterCount, int lineCount)
用于文件1和
void PrintLines(char characterValue, int characterCount, int lineCount);
用于主。我可能需要将ascii转换为char ...
您可以像这样过载函数,但是两个函数具有不同的签名,即在链接过程中会失败。我不确定您要实现的目标,但可能会委派它:
void PrintLines(char cv, int cc, int lc) {
PrintLines(int(cv), cc, lc);
}
如果要传递char
而不是int
作为第一个参数,则只需这样做即可。示例:
int x, y;
char c;
// ...
PrintLines(c, x, y);
char
可以隐式地施放于C 中的int
。如果您喜欢:
int
进行手册。 PrintLines(static_cast<int>(c), x, y);
,所以我发现了它。
cout&lt;&lt;(char)tramevalue;
在带有函数的文件中。
我的A获得了65
相关文章:
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 多维数组 C++ 中数组下标的类型"int[int]"无效
- 指针问题:从不兼容的类型"int"分配给"int *"
- 数组类型 int[n][n] 不可赋值,因为表达式必须具有常量值
- 错误:数组下标的类型"int[int]"无效
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 类型为 "int*" 的参数与 C++ 中错误类型"int**"参数不兼容
- 类型"int"和"const char [15]"到二进制"运算符<<"的无效操作数^
- 从类型bankAccount的返回值到函数返回类型int没有可行的转换
- for 循环说 - 错误 成员引用基类型"int [13]"不是结构或联合
- 运行时错误:有符号整数溢出:964632435 * 10 无法在类型 'int' 中表示
- 如何增加模板类型 int 参数?
- 尝试使用 Array 类的模板构造整数数组时,错误:为什么数组类型"int [5]"不可分配,
- 如何为底层类型 int 的枚举专门化类
- 数组下标编译的无效类型'int[int]'由于 -Wfatal 错误而终止
- 不能将 "const char*" 类型的值分配给类型 "int" 的实体
- 数组下标的无效类型INT [INT]
- 请求在"伺服控制器"中请求成员"附加",该成员属于非类类型"int"
- 数组类型 'int [8]'不可分配
- 未声明的标识符和类型"int"从 main 调用类时出现意外错误