#include <iostream> #include <stdlib.h> using namespace std; class xiaok{ public: int k; int a; void han(){cout<<k<<a<<endl;} }; int main(int argc, char const *argv[]) { xiaok *p=(xiaok*)malloc(sizeof(xiaok)); new(p) xiaok(); p->a=10; p->k=20; p->han(); return 0; } //////////------------------------- #include <iostream> #include <stdlib.h> using namespace std; class xiaok{ public: int k; int a; void han(){cout<<k<<a<<endl;} }; int main(int argc, char const *argv[]) { void *p=malloc(sizeof(xiaok)); new(p) xiaok(); xiaok *vp=(xiaok*)p; vp->a=10; vp->k=20; vp->han(); return 0; }
时间: 2024-10-24 00:57:34