C++ compilation error
1 次查看(过去 30 天)
显示 更早的评论
Dear all,
Why am I getting this error when I compile using mex. when I compile using Xcode 'clang++' everything is fine.
******************************
#include <iostream>
#include "mex.hpp"
#include "mexAdapter.hpp"
using namespace std;
using namespace matlab::data;
using matlab::mex::ArgumentList;
class Z {
public:
void get (){
cin>> x;
}
void print (){
cout<<"the integer:" << x;
}
private:
int x;
};
class MexFunction : public matlab::mex::Function {
Z abd;
abd.get();
abd.print();
};
***************************************error*************>>
mex -setup C++
MEX configured to use 'Xcode Clang++' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
>> mex maher1.cpp
Building with 'Xcode Clang++'.
Error using mex
/Users/maherheal/Dropbox/maherphd/1UK/Last/Code_v3/maher1.cpp:22:5: error: unknown type name 'abd'
abd.get();
^
/Users/maherheal/Dropbox/maherphd/1UK/Last/Code_v3/maher1.cpp:22:8: error: expected member name or ';'
after declaration specifiers
abd.get();
~~~^
/Users/maherheal/Dropbox/maherphd/1UK/Last/Code_v3/maher1.cpp:23:5: error: unknown type name 'abd'
abd.print();
^
/Users/maherheal/Dropbox/maherphd/1UK/Last/Code_v3/maher1.cpp:23:8: error: expected member name or ';'
after declaration specifiers
abd.print();
~~~^
4 errors generated.
0 个评论
采纳的回答
Viggnesh Venkatakrishnan
2018-12-17
Hi Maher,
I understand that you are having a problem with compiling the given code using MEX. I tried reproducing the issue at my end and observed the following:
class MexFunction : public matlab::mex::Function {
Z abd;
abd.get();
abd.print();
};
In the above part of the code MexFuntion is a class which has an object of the class Z as one of the data members. The next line of the code calls the member funtion of class Z using the same object that was created. C++ does not allow a funtion/Method call directly inside a class. You can do it in the following way instead:
class MexFunction : public matlab::mex::Function {
Z abd;
MexFuntion()
{
abd.get();
abd.print();
}
};
In the above code snippet, the Method of class Z is being called after the Data member abd has been constructed.
If you can any specific questions regarding c++ mex please refer to the example given in the doc :https://www.mathworks.com/help/matlab/matlab_external/c-class-in-mex-files.html
Thank you ,
Viggnesh Venkatakrishnan
2 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!