我是C ++的新手,我有一个返回内存位置地址的函数,我想将该地址分配给一个指针,就像:
unsigned int address = 0xdeadbeef;
unsigned int* memory_ptr = (unsigned int*) address;
但是上面的代码是通过警告:
cast to pointer from integer of difference size [-Wint-to-pointer-cast]
反正有没有用C ++干净地完成此任务?
答案 0 :(得分:0)
您可以使用public class Solution {
public static void main(String[] args) {
Man man1 = new Man(); // first way to create object
Man man2 = new Man("dhiraj",28,"Indore"); // second way to create object
System.out.println(man2.name + "" + man2.age + "" + man2.address);
Woman woman1 = new Woman(); // first way to create object
Woman woman2 = new Woman("dhiraj",28,"Indore"); // second way to create object
System.out.println(woman2.name + "" + woman2.age + "" + woman2.address);
//write your code here
}
}
class Man
{
private String name, address;
private int age;
public Man()
{
}
public Man(String name, int age, String address) {
this.name = name;
this.age = age;
this.address = address;
}
}
class Woman
{
private String name, address;
private int age;
public Woman()
{
}
public Woman(String name, int age, String address) {
this.name = name;
this.age = age;
this.address = address;//write your code here
}
}
代替unsigned int
。
整数类型,该类型可以保存从void指针转换的值,然后将其转换回具有与原始指针相等的值的该类型。