标签: casting

为什么在IF语句中检查void函数时会发生语法错误

如果我写的话会有什么输出

在C++ if(5)中执行没有任何问题但在C#中不会以相同的方式运行它.

if(func()){} //in C# it doesn't runs Why how does C# treats void and how in Turbo C++

void func()
{
return;
}

if(null==null){}//runs in C#
Run Code Online (Sandbox Code Playgroud)

编辑

if(printf("Hi"){} //will run and enter into if statement

if(printf(""){}//will enter into else condition if found.
Run Code Online (Sandbox Code Playgroud)

本课题不适用于那些不了解Turbo Compiler的人

c# c++ casting conceptual void

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

在Java中使用Reflections时出错

我在此代码中遇到了转换问题,但不知道如何纠正它.

public void showFrame(String className, Object controller) throws Exception{
    try {
       Class c = Class.forName("com." + className);
       // "(Object.class)" I want this to be of type held in className var
       // this type will be same as one passed into  "controller" at runtime
       Constructor ctr = c.getConstructor(Object.class);  
       ctr.newInstance(controller);
    } catch (ClassNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error" );
    }
}
Run Code Online (Sandbox Code Playgroud)

java reflection casting

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

c#获取混合类型列表中元素的属性

我有一个列表:圆形,三角形,矩形

我想编辑id为X的元素,但列出[X] .radius; 不可用,因为它是一个儿童班.

c# casting list

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

链接继承时的输出

class Monster {
    boolean frighten(int x) {
        System.out.println("Monster");
        return true;
    }
}

class Vampire extends Monster {
    boolean frighten(byte x) {
        System.out.println("Vampire");
        return true;
    }
}

class Dragon extends Monster {
    boolean frighten(int x) {
        System.out.println("Dragon");
        return true;
    }
}


class Sample {
    public static void main(String s[]) {
        Monster[] inst = new Monster[3];
        inst[0] = new Monster();
        inst[1] = new Vampire();
        inst[2] = new Dragon();

        for (int i = 0; i < 3; i++) {
            inst[i].frighten(i);
        }
    }
} …
Run Code Online (Sandbox Code Playgroud)

java inheritance casting

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

作为String转换为Int失败

我的prepareForSegue电话问题一直存在.每当我尝试segue到下一个视图控制器.它会在我将tripLikes传递给下一个视图控制器时出现错误并崩溃.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "toDetailScene") {


        //Hooking up places-holder values
        let viewController = segue.destinationViewController as! DetailViewController

        let cell = sender as! CustomPFTableViewCell


        viewController.tripName = cell.nameTextLabel.text!
        viewController.tripAuthor = cell.authorTextLabel.text!
        viewController.tripLikes = Int(cell.numLikes.text!)!
        viewController.tripDescrip = cell.descriptionHolder

    }
}
Run Code Online (Sandbox Code Playgroud)

我们传递给的每个值都是目标视图控制器中的值.

casting uitableview ios swift

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

初始化使得整数指针没有强制转换

我已经尝试了*和s的所有可能组合.我无法弄清楚这个程序有什么问题以及导致这个编译时错误的原因

我收到这个错误:

error: initialization makes pointer from integer without a cast
compilation terminated due to -Wfatal-errors.
Run Code Online (Sandbox Code Playgroud)

使用此代码:

int main() {
  unsigned int ten = (int) 10;
  unsigned short *a = (short) 89; 
  unsigned int *p =(int)  1;
  unsigned short *q = (short) 10;
  unsigned short *s = (short) 29;


  function(ten,a,p, q, s);

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

功能原型是:

int function(unsigned int a, unsigned short *const b,
                   unsigned int *const c,
                   unsigned short *const d,
                   unsigned short *const e);
Run Code Online (Sandbox Code Playgroud)

该函数为空,我只是想用输入文件编译它.

c linux pointers casting compiler-errors

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

任何人都可以向我解释以下内容

任何人都可以向我解释在下面的代码片段的运行时期间发生了什么,为什么它打印33?谢谢,

#include <stdio.h>

void main(){
    int* p = (int*)17;
    printf("%d\n", (int)(long)(p+4));
}
Run Code Online (Sandbox Code Playgroud)

c pointers casting

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

数组指针到数组的转换 - C / C++ 初学者

我有一个数组:

\n\n
unsigned char data[dataLength];\n
Run Code Online (Sandbox Code Playgroud)\n\n

和一个函数:

\n\n
unsigned char* get_data(int length)\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想将函数的返回值分配给变量。

\n\n

当我直接做的时候

\n\n
data = get_data(length);\n
Run Code Online (Sandbox Code Playgroud)\n\n

编译器抱怨:

\n\n
\n

将 \xe2\x80\x98unsigned char*\xe2\x80\x99 分配给 \xe2\x80\x98unsigned char [(((sizetype)(((ssizetype)frameLength) + -1)) + 1)]\ 时的类型不兼容xe2\x80\x99

\n
\n\n

它与 memcpy 一起使用:

\n\n
memcpy(data, get_data(dataLength), dataLength);\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我不想再次复制数据。

\n\n

有人可以帮忙吗?

\n

c arrays pointers casting

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

从父母到孩子的堕落c#

所以我无法想象我的生活.我尝试过多种形式的演员.

这是父母.

    /// <summary>
    /// Colour Parent
    /// </summary>
    public class Colour
    {

        #region Public Fields

        public float R;
        public float G;
        public float B;
        public float A;

        #endregion Public Fields
    }
Run Code Online (Sandbox Code Playgroud)

而这就是孩子.哪个有预先定义的变量.意味着它具有向下传播所需的所有信息.

    /// <summary>
    /// Data strucutre extension of Base.Colour, Used for the variables stored inside the glow object in memory
    /// </summary>
    public class GlowStruct : Colour
    {
        public bool RWO  = true;
        public bool RWUO = true;
    }
Run Code Online (Sandbox Code Playgroud)

我试着用它来施展.

return Base.Blue as GlowStruct;
Run Code Online (Sandbox Code Playgroud)

Base.Blue是Color类的静态成员.使用"is"返回false.

不知道为什么你需要Base.Blue的定义看作是它的正数.我已经提到它是一个静态类.

public static …
Run Code Online (Sandbox Code Playgroud)

c# inheritance casting downcast

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

我是否在 C++ 中转换 new 的结果?

在问题的答案中,Do I cast the result of malloc? 涵盖了我不需要也不应该在 C 中转换返回的void指针malloc()

但是newC++ 中的运算符如何呢?


是否有明确的理由只做

int *p_rt = new int;
Run Code Online (Sandbox Code Playgroud)

代替

int *p_tr = (int*) new int;
Run Code Online (Sandbox Code Playgroud)

或者我可以做演员吗?

c++ casting heap-memory new-operator

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