#include <iostream>
using namespace std;
class user
{
public:
int age;
int number;
void test()
{
printf("this is user test function \t");
}
virtual void test1()
{
printf("this is user test111 function \t");
}
};
int main()
{
//user *u=new user();
user *u=(user *)malloc(sizeof(user));
u->age=90;
u->number=100;
u->test();
//u->test1();
free(u);
cout << "Hello World";
return 0;
}
-------------------------------------------------------结果----------------------
this is user test function Hello World
打开注解test1
----------------------------------------------
run: line 1: 3 Segmentation fault (core dumped) LD_LIBRARY_PATH=/usr/local/gcc-9.2.0/lib64 ./a.out
Exited with error status 139
原文:https://www.cnblogs.com/bruce1992/p/14095471.html