如果我写的话会有什么输出
在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的人
我在此代码中遇到了转换问题,但不知道如何纠正它.
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) 我有一个列表:圆形,三角形,矩形
我想编辑id为X的元素,但列出[X] .radius; 不可用,因为它是一个儿童班.
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) 我的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)
我们传递给的每个值都是目标视图控制器中的值.
我已经尝试了*和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)
该函数为空,我只是想用输入文件编译它.
任何人都可以向我解释在下面的代码片段的运行时期间发生了什么,为什么它打印33?谢谢,
#include <stdio.h>
void main(){
int* p = (int*)17;
printf("%d\n", (int)(long)(p+4));
}
Run Code Online (Sandbox Code Playgroud) 我有一个数组:
\n\nunsigned char data[dataLength];\nRun Code Online (Sandbox Code Playgroud)\n\n和一个函数:
\n\nunsigned char* get_data(int length)\nRun Code Online (Sandbox Code Playgroud)\n\n我想将函数的返回值分配给变量。
\n\n当我直接做的时候
\n\ndata = get_data(length);\nRun Code Online (Sandbox Code Playgroud)\n\n编译器抱怨:
\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
它与 memcpy 一起使用:
\n\nmemcpy(data, get_data(dataLength), dataLength);\nRun Code Online (Sandbox Code Playgroud)\n\n但我不想再次复制数据。
\n\n有人可以帮忙吗?
\n所以我无法想象我的生活.我尝试过多种形式的演员.
这是父母.
/// <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) 在问题的答案中,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)
或者我可以做演员吗?
casting ×10
c ×3
c# ×3
pointers ×3
c++ ×2
inheritance ×2
java ×2
arrays ×1
conceptual ×1
downcast ×1
heap-memory ×1
ios ×1
linux ×1
list ×1
new-operator ×1
reflection ×1
swift ×1
uitableview ×1
void ×1