[C++] About pointer to base class

2019-4-29 写技术

#include <stdio.h>
#include <stdlib.h>

class base{
public:
	int a;
	int b;
	int c;	
};

class hello:public base{
public:
	int c;
	int d;
	
};

int main(){
	base b;
	b.a = 1;
	b.b = 2;
	b.c = 5;

	hello *c;
	c =(hello *)&b;

	c->d = 3;
	
	printf(" %d %d %d %d\n", c->a, c->b, c->c, c->d);
}

标签: C++

发表评论:

Powered by anycle 湘ICP备15001973号-1