小编use*_*939的帖子

g ++在基类中找不到重载函数

以下不用(GCC)4.8.2编译.它抱怨这样:

错误:没有匹配函数来调用'classderivedderived :: dump(int)'

#include <iostream>

class classbase{
public:
    void print() {std::cout << "base\n";}
    virtual void dump() = 0;
    void dump(int i) {std::cout << i << " blech\n";}
    int i;
};

class classderived : public classbase {
public:
    int ii;
};

class classderivedderived : public classderived {
public:
    void dump() {std::cout << "blah\n"; dump(10);}
    int iii;
};

int main() {
    classderivedderived yellow;
    yellow.i = 5;
    yellow.dump();
}
Run Code Online (Sandbox Code Playgroud)

它确实编译并运行

(1) dump(10) => classbase::dump(10)

要么

(2) dump(10) => puddledump(10) and void dump(int …

c++ inheritance gcc

1
推荐指数
1
解决办法
610
查看次数

MEX调用后,MATLAB数组分配失败

我正在与MEX合作并获得奇怪的行为,我将其分离到以下非常简单的程序:

#include "mex.h"
#include <stdio.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  double *A;
  int i;

  if (    nrhs != 1
       || nlhs > 1
       || !mxIsDouble(prhs[0])
       || mxIsComplex(prhs[0])
       || mxGetM(prhs[0])!=1
    ) mexErrMsgTxt("internal error: dtimes2: input error");

  A = mxGetPr(prhs[0]);
  for (i=0; i<3; i++) A[i] *= 2;
  return; }
Run Code Online (Sandbox Code Playgroud)

所以问题是这样的:在MATLAB会话中,

B=[3.2,5.6,9.4]; dtimes2(B); B
Run Code Online (Sandbox Code Playgroud)

和MATLAB说:B = 6.4000 11.2000 18.8000

到现在为止还挺好.但现在:

B=[3.2,5.6,9.4]
Run Code Online (Sandbox Code Playgroud)

和MATLAB说:B = 6.4000 11.2000 18.8000

但是当我说

B=[-34.5,-57.6,-28.9]
Run Code Online (Sandbox Code Playgroud)

然后MATLAB说:B = -34.5000 -57.6000 -28.9000

你看到中间我不能重新分配B,如果数字与以前相同.所以,现实检查:

A=[1,2,3]; A=2*A; A=[1,2,3] …
Run Code Online (Sandbox Code Playgroud)

c++ matlab mex

1
推荐指数
1
解决办法
53
查看次数

标签 统计

c++ ×2

gcc ×1

inheritance ×1

matlab ×1

mex ×1