C++中没有匹配的函数:将常量标记添加到调用函数 我刚开始在C++的领域冒险,所以这可能是个愚蠢的问题。我从我的编译器中得到以下错误

C++中没有匹配的函数:将常量标记添加到调用函数 我刚开始在C++的领域冒险,所以这可能是个愚蠢的问题。我从我的编译器中得到以下错误,c++,compiler-errors,C++,Compiler Errors,Run.cc:56:错误:调用“sphereDetect::getArrayPtr const”时没有匹配的函数 /spheredetect.hh:18:注意:候选对象是:constg4long*spheredetect::getArrayPtr[36][72][60] 我的Run.hh是: 我的Run.cc是: 我完全不知道如何解决这个问题。这是我构造或调用sphereDetect类的方式吗?可以肯定的是,Run.Merge的输入必须是基于前面代码的输入 非常感谢您的帮助 将 你缺一个常数 这

Run.cc:56:错误:调用“sphereDetect::getArrayPtr const”时没有匹配的函数 /spheredetect.hh:18:注意:候选对象是:constg4long*spheredetect::getArrayPtr[36][72][60]

我的Run.hh是:

我的Run.cc是:

我完全不知道如何解决这个问题。这是我构造或调用sphereDetect类的方式吗?可以肯定的是,Run.Merge的输入必须是基于前面代码的输入

非常感谢您的帮助

将 你缺一个常数

这意味着返回一个常量指针

 const arr* getArrayPtr() const {}
这意味着它返回一个常量指针,并且可以在常量对象上调用。否则,编译器无法判断getArrayPtr是否不想修改调用它的对象


由于localRun是const,它的成员localRun->scatter也是const。

编译器正在寻找getArrayPtr的定义,该定义声明它不会修改对象,因此可以安全地调用const对象。这是通过将常量放在函数签名的其余部分之后来完成的,就像G4double GetEdep const一样

const-arr*getArrayPtr{}应该是const-arr*getArrayPtr-const{}。
#include "Run.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Run::Run()
: G4Run(),
  fEdep(0.),
  fEdep2(0.),
  scatter()
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

Run::~Run()
{}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void Run::Merge(const G4Run* run)
{


  const Run* localRun = static_cast<const Run*>(run);
  fEdep  += localRun->fEdep;
  fEdep2 += localRun->fEdep2;
  arr* scatterPointer = localRun->scatter.getArrayPtr();
  scatter.sphereMerge(scatterPointer);
  G4Run::Merge(run);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void Run::AddEdep (G4double edep)
{
  fEdep  += edep;
  fEdep2 += edep*edep;
}
typedef G4long arr[36][72][60];
class sphereDetect
{
public:
    sphereDetect();
     ~sphereDetect();
      const arr* getArrayPtr() {return &scatterArray;}
     void sphereMerge(arr*);
     void createHit(G4ThreeVector,G4double);
protected:
     void storeHit(G4int,G4int,G4int);
     G4int findAngNS(G4ThreeVector);
     G4int findAngEW(G4ThreeVector);
     G4int findEnergy(G4double);

     void sphereSave();

private:


    G4long scatterArray[36][72][60];

};
 const arr* getArrayPtr() {}
 const arr* getArrayPtr() const {}