passing string to a function

Pranav

I'm trying to pass a string to a function, which works fine when I use in Visual studio but I need run my code in linux with eclipse CDT as my IDE. The reason for choosing eclipse is I need to access matlab's engine.h in linux enviornment which is possible through eclipse.

I'm calling a function MputVar2d(x, "x"); where x is a vector <vector<double> > and "x" is a string. and my function which is written in different header file is:

template <typename T>
void MputVar2d(const vector <vector<T> > &var, string name){
    extern Engine *ep;
    int row = var.size(), col = var[0].size();
    mxArray *matlab = mxCreateDoubleMatrix(row, col, mxREAL);
    T *pa = mxGetPr(matlab);
    for (int j = 0; j < var[0].size(); j++){
        for (int i = 0; i < var.size(); i++){
            pa[i * row + j] = var[i][j];
        }
    }
    engPutVariable(ep, name.c_str(), matlab);
}

I get the following error when I'm running my code:

Invalid arguments:
Candidates are:
void MputVar2d(const std::vector<std::vector<#0,std::allocator<#0>>,std::allocator<std::vector<#0,std::allocator<#0>>>> &, std::basic_string<char,std::char_traits<char>,std::allocator<char>> &)

I tried executing my function as MputVar2d(x, string("x"));, or defining string as std::string& but it still gives the error.

Vlad.Z

The 2nd argument is a non-const string reference, judging by error message. You should make it const string& unless you are changing the string in the function and want the caller to see the change.

If you need more details, I will elaborate later today. For quick fix just change the function to take const string& name and you'll be fine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing string parameter in JavaScript function

From Dev

Passing a string to function but expecting an array

From Dev

Passing a string to pthread function

From Dev

Passing a String Array to a Function

From Dev

Trouble with passing string to function

From Dev

Passing String to Import Function React

From Dev

Passing string from a function into another function

From Dev

Passing HTML string to JavaScript function

From Dev

passing string to ggplot function

From Dev

passing a string into a function

From Dev

Passing string parameters in JQuery function

From Dev

Passing encoded string to Javascript function

From Dev

Passing a string as a keyed argument to a function

From Dev

Passing a pointer (string) to a C function

From Dev

alert by passing string to alert function

From Dev

Passing default string pointer to function

From Dev

String vectors not passing to a class function

From Dev

Passing spaced string as argument to function

From Dev

Passing null string to function as an argument

From Dev

C passing string to function issue

From Dev

Passing path string to a jquery function

From Dev

Passing swift string to c function char *

From Dev

Passing string into a lambda function

From Dev

Passing a string array to another function

From Dev

Passing input string to a function in C

From Dev

Passing a string to a handler function in Go

From Dev

passing function statement as string in terraform

From Dev

passing a string variable to a function np.array

From Dev

Passing string in an onclick function