필터 지우기
필터 지우기

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 CenterFile Exchange에서 Write 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