- 论坛徽章:
- 0
|
mathgl.h- #include <mgl/mgl_c.h>
- class mglGraph {
- HMGL gr;
- public:
- mglGraph(int kind, int width, int height);
- ~mglGraph();
- };
复制代码 mathgl.cpp- #include "mathgl.h"
- #include <iostream>
- using namespace std;
- mglGraph::mglGraph(int kind, int width, int height) {
- std::cout << "new" << std::endl;
- if (kind == 0)
- gr = mgl_create_graph_zb(width, height);
- else if (kind == 1)
- gr = mgl_create_graph_ps(width, height);
- }
- mglGraph::~mglGraph() {
- std::cout << "delete" << std::endl;
- mgl_delete_graph(gr);
- }
复制代码 exam.cpp- #include <iostream>
- #include "mathgl.h"
- using namespace std;
- int main() {
- mglGraph w(1,1,1);
- return 0;
- }
复制代码 运行输出如下:
new
delete
delete
Segmentation fault
为什么析构函数调用了两次,如何让它只调用一次?谢谢! |
|