Azzera filtri
Azzera filtri

C++ compilation error

4 visualizzazioni (ultimi 30 giorni)
Maher
Maher il 31 Ott 2018
Commentato: Walter Roberson il 21 Dic 2018
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.

Risposta accettata

Viggnesh Venkatakrishnan
Viggnesh Venkatakrishnan il 17 Dic 2018
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 Commenti
Maher
Maher il 21 Dic 2018
Thank you very much!
Walter Roberson
Walter Roberson il 21 Dic 2018
Is MexFuntion() a typing mistake ? Should it be MexFunction() ?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by