フィルターのクリア

C++ compilation error

4 ビュー (過去 30 日間)
Maher
Maher 2018 年 10 月 31 日
コメント済み: Walter Roberson 2018 年 12 月 21 日
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.

採用された回答

Viggnesh Venkatakrishnan
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 件のコメント
Maher
Maher 2018 年 12 月 21 日
Thank you very much!
Walter Roberson
Walter Roberson 2018 年 12 月 21 日
Is MexFuntion() a typing mistake ? Should it be MexFunction() ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by