我有一个程序可以创建对象“图表”并用数据填充它们。之后,我尝试将指向这些对象的指针发送到 diagram.exe,以便它绘制图表。我使用 _spawnv,并且 diagram.exe 获得的指针与我发送的指针不同。我做错了什么?有没有更合适的方法呢?提前致谢。
//这是调用diagram.exe的程序
#include<conio.h>
#include<math.h>
#include<process.h>
#include<iostream>
using std::cout;
using std::endl;
int main()
{
Diagram** diagrams = new Diagram*[2];
diagrams[0] = new Diagram(1001, "sin(x)");
diagrams[1] = new Diagram(150, "atan(x)");
diagrams[2] = NULL;
double x = -2.0;
for(int i = 0; i < 1001; i++)
{
diagrams[0]->points[i].x = x;
diagrams[0]->points[i].y = sin(x);
diagrams[0]->points[i].flag = true;
diagrams[0]->points[i].radius = 4;
diagrams[1]->points[i].x = x;
diagrams[1]->points[i].y = atan(x);
diagrams[1]->points[i].flag = true;
diagrams[1]->points[i].radius = 5;
x += 0.004;
}
cout << "CallDiagram.exe: diagrams: " << (void*)diagrams << endl;
char* args[3] = {"diagram.exe", (char*)diagrams, NULL};
_spawnv(_P_WAIT, "..\\..\\diagram\\Debug\\diagram.exe", args);
_getch();
delete diagrams[0];
delete diagrams[1];
delete [] diagrams;
return 0;
}
//图表.cpp
#include "diagram.h"
#include "DrawDiagram.h"
int main(int argc, char* argv[])
{
if(argc <= 1)
{
cout << "\ndiagram.exe: No arguments!" << endl;
return 1;
}
Diagram** diagrams = (Diagram**)argv[1];//NULL;
cout << "diagram.exe: diagrams: " << (void*)diagrams << endl;