标签: implicit-conversion

Visual Basic 6 如何将整数转换为布尔值?

我正在 vb6 中阅读以下代码

If someInteger Then
    DoSomething
End If
Run Code Online (Sandbox Code Playgroud)

不知道是不是这个意思

  1. someInteger == 1,
  2. someInteger > -1,
  3. someInteger > 0 或者
  4. Convert.ToBoolean(someInteger)

C# 中的等价表达式是什么?

vb6 integer boolean vb6-migration implicit-conversion

2
推荐指数
1
解决办法
1293
查看次数

C++指针类型的隐式转换

考虑这个案例:

int *ptr;
int offset;
ptr = <some_address>;
offset = 10;
Run Code Online (Sandbox Code Playgroud)

假设它offset是 32 位变量。ptr具有 type int*,目标体系结构是 64 位(ptr8 字节变量也是如此),offset具有 type int。计算表达式的值时会进行什么转换*(ptr + offset)?我在哪里可以在 2003 C++ 标准中阅读它?

c++ implicit-conversion pointer-conversion

2
推荐指数
1
解决办法
804
查看次数

使用转换运算符初始化地图

是什么阻止了这个初始化工作?

#include <map>
using std::map; using std::pair; using std::make_pair;
struct P {
    char a_, b_;
    P(char a, char b) : a_{a}, b_{b} {}
    operator pair<char,char>() { return make_pair(a_, b_); }
};
int main() {
    map<char,char> qmap { P( 'a','b' ) };
}
Run Code Online (Sandbox Code Playgroud)

看起来转换运算符 inP不能隐式应用在花括号初始化列表中?或者是别的什么?

c++ initializer-list implicit-conversion

2
推荐指数
1
解决办法
108
查看次数

kotlin - 数字类型的自动转换

在java中,我们可以赋值intdouble,例如double x = 123

在 kotlin 中,我们得到了一个编译错误。

问题:我们可以在 中启用自动转换功能kotlin吗?为什么kotlin默认没有这个功能?

var x: Double = 123; // ERROR
Run Code Online (Sandbox Code Playgroud)

再举一个例子:

fun foo(x: Double) { }

fun main(args: Array<String>) {
   foo(123.0);  // OK 
   foo(123);    // ERROR
}
Run Code Online (Sandbox Code Playgroud)

更新:

文字123可以在编译时自动转换为ShortLong。但它不会转换为FloatDouble

fun fooShort(x: Short) {}
fun fooInt(x: Int)     {}
fun fooLong(x: Long)   {}


fun main(args: Array<String>) {
    fooShort(123)  // OK
    fooInt(123)    // OK
    fooLong(123) …
Run Code Online (Sandbox Code Playgroud)

type-conversion implicit-conversion kotlin

2
推荐指数
1
解决办法
1794
查看次数

为什么二维数组的行为类似于一维指针数组而不是一维整数数组?

我一直在研究和测试我在 C 方面的知识(我是一名新的计算机工程专业的学生),遇到了一个我无法弄清楚的问题。

在尝试将 2D 数组传递给函数时,我了解到您不能使用动态分配的数组这样做,因为编译器需要知道 array[][columns]。但是,我了解到二维数组存储在一维数组中,其中每个新行的元素都跟在前一行的元素之后。当我将数组名称作为指向数组的指针传递给函数时,情况似乎如此,我的代码运行良好。但是,在声明 2D 数组的函数中,它表现为一个指针数组。

#include <stdio.h>

void printArray(int *A, int* dimA) {
    for(int i = 0; i < dimA[0]; ++i) {
        for(int j = 0; j < dimA[1]; ++j) {
            printf("%3d", A[i*dimA[1] + j]);//This would work if the elements of A[] are the rows of a 2D array mapped into a 1D array
        }
    printf("\n\n");
    }
return;
}

int main(){
    int A[2][2] = {{1,2},{3,4}};
    int dimA[2] = {2,2};//dimensions of the array
    int i, j; 

    for(i …
Run Code Online (Sandbox Code Playgroud)

c arrays pointers multidimensional-array implicit-conversion

2
推荐指数
1
解决办法
563
查看次数

char *a[]={"hello", "world"}; 和有什么区别?和字符 a[][10]={"hello", "world"};?

当我尝试这段代码时

char *a[] = {"hello", "world" };
char **p = a;
char a[][10]={"hello", "world"};
Run Code Online (Sandbox Code Playgroud)

我的编译失败,我被告知变量 a 存在冲突类型错误。顶部声明与底部声明有何不同?

c arrays pointers declaration implicit-conversion

2
推荐指数
2
解决办法
325
查看次数

将 unsigned int 的最大值转换为 int 并期望结果为 -1 是否可移植?

我找到了一个 C++ 代码,我们将初始化为最大值的 unsigned int 32 转换为有符号 int 并期望它是-1. 它在经过测试的编译器上运行良好,但它真的可移植吗?

int GetBusinessDataID()
{
    u32_t id = ~0;

    // Some code that may return a valid ID.

    return id; // Here we expect to return -1.
}
Run Code Online (Sandbox Code Playgroud)

c++ unsigned implicit-conversion

2
推荐指数
1
解决办法
82
查看次数

如何从指针中减去字符数组?

所以,我开始熟悉 C,在这一点上我试图理解指针。我从这里得到以下代码,但我无法理解,如何从指针中减去字符数组。

#include<stdio.h>
#include<string.h>
#include<conio.h>

main() 
{   
char s[30], t[20];   
char *found; 

/* Entering the main string */   
puts("Enter the first string: ");   
gets(s);

/* Entering the string whose position or index to be displayed */   
puts("Enter the string to be searched: ");   
gets(t);

/*Searching string t in string s */   
found=strstr(s,t);   
if(found)
    printf("Second String is found in the First String at %d position.\n",found-s);    
else
    printf("-1");   
getch(); 
}
Run Code Online (Sandbox Code Playgroud)

指针不只是给定变量/常量的地址吗?当减法发生时,字符数组会自动假设,因为操作是用指针发生的,所以减去它的地址?我在这里有点困惑。

提前致谢。

c arrays pointers pointer-arithmetic implicit-conversion

2
推荐指数
1
解决办法
92
查看次数

为什么我们不能将数组地址分配给指针?

int q[10]={0};
cout << q << endl;
cout << &q << endl;
cout << &q[0] << endl;
Run Code Online (Sandbox Code Playgroud)

输出是

0x7fffd4d2f860 
0x7fffd4d2f860 
0x7fffd4d2f860 
Run Code Online (Sandbox Code Playgroud)

现在当我这样做时->

int *r=q;    // allowed
int *r=&q[0] // allowed
int *r=&q    // not allowed
Run Code Online (Sandbox Code Playgroud)

为什么在本质上是同一件事时不允许第三次赋值?

c++ arrays pointers declaration implicit-conversion

2
推荐指数
1
解决办法
375
查看次数

在 dart 中将 int 转换为 bool

我有一个从 JSON 导出的不同类型值的列表。

class StudentDetailsToMarkAttendance {
  int att_on_off_status;
  String name;
  String reg_number;
  int status;

  StudentDetailsToMarkAttendance(
      {this.att_on_off_status, this.name, this.reg_number, this.status});

  factory StudentDetailsToMarkAttendance.fromJson(Map<String, dynamic> json) {
    return StudentDetailsToMarkAttendance(
      att_on_off_status: json['att_on_off_status'],
      name: json['name'],
      reg_number: json['reg_number'],
      status: json['status'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['att_on_off_status'] = this.att_on_off_status;
    data['name'] = this.name;
    data['reg_number'] = this.reg_number;
    data['status'] = this.status;
    return data;
  }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用status的值作为Checkbox. 我正在尝试解析intString喜欢这个。

value:((widget.studentDetailsList[index].status = (1 ? true : …
Run Code Online (Sandbox Code Playgroud)

implicit-conversion dart flutter

2
推荐指数
3
解决办法
6680
查看次数