using std::vector<double> inside mexfunction()

1 次查看(过去 30 天)
hi,
i have the following
----myfunction.cpp------
#include<mex.h>
#include<math.h>
#include<matrix.h>
#include<stdio.h>
#include "mydllfunctionheader.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mystruct XXX;
XXX.a=0;
XXX.b.resize(10,0.);
mydllfunction(XXX);
}
----mydllfunctionheader.h----
#include <vector>
#include <map>
struct mystruct
{
double a;
std::vector<double> b;
}
__declspec(dllexport) int __cdecl
mydllfunction(mystruct XXX);
----------------------
problem is inside the mexfunction i make XXX.b to be of size 10 vector. but in the debug mode when i enter the mydllfunction the vector b gets messed up. any doubles (such as variable "a") are okay but any vectors are not okay.
Can anyone please comment on what is going on.
also i cannot have extern "C" before my _declspec. becuase though in the simple example i provide above i am returning int in the actual case i will be returning an complex object.
thanks in advance

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by