1

I am fairly new to C++ and this method just won't overload in Vector class.

class Vector {
...
     void findTriDiagonalDeterminant(mpf_t *det, unsigned long long *d, double offset) {
          ...
     }

     void findTriDiagonalDeterminant(mpf_t *det, unsigned long long *d) {
          findTriDiagonalDeterminant(det, d, 0);
     }
}

class Matrix : public Vector {
private:
    unsigned long long* dims;
public:
    void findTriDiagonalDeterminant(mpf_t* det, int index) {
        Vector::findTriDiagonalDeterminant(det, dims+index);
    }
    ...
}

The g++ says

error: no matching function for call to ‘Matrix::findTriDiagonalDeterminant(__mpf_struct (*&)[1], long long unsigned int*)’

But there's a matching function: second one from the top in Vector class.

I tried the same without pointers (by substituting *d with d and dims+index by *(dims+index)) but it didn't help.

2
  • Seems like findTriDiagonalDeterminant isn't actually a method. A method is a virtual function.
    – Aleph
    Dec 20, 2012 at 17:05
  • "method" is not a technical term in the C++ Standard. Depending on who you ask, informally for C++ it can mean "virtual function" or just "member function".
    – aschepler
    Dec 20, 2012 at 17:10

2 Answers 2

4

In C++ overloads in a child class hide the methods in the parent class, so only the function in Matrix can be called with a Matrix.

You can use using to expose the extra methods, something like this.

class Matrix : public Vector {
private:
   unsigned long long* dims;
public:
   using Vector::findTriDiagonalDeterminat;
   void findTriDiagonalDeterminant(mpf_t* det, int index) {
     Vector::findTriDiagonalDeterminant(det, dims+index);
   }
...
}
3
  • It didn't help. Besides I refer to it explicitly - Vector::, so wouldn't it make using redundant? Dec 20, 2012 at 17:02
  • Didn't realize what line it was complaining about. This compiles for me with Visual Studio. Are the methods private in Vector? Do both classes have mpf_t defined as the same type? Dec 20, 2012 at 18:48
  • 2
    @ArtiomFiodorov Since vector is qualified explicitly it cannot be that function call, since the compiler error mentions Matrix::function(...). (if it was the call in Matrix, it would complain about the Vector::function(...)) Post the callsite where you actually use the Matrix class to call a function.
    – Max
    Dec 20, 2012 at 18:54
1

I'm guessing (dims+index) is getting promoted to something else. Maybe try explicitly casting the result or assign the expression to an appropriate temporary variable.

1
  • unsigned long long * pointer = dims+index; Vector::findTriDiagonalDeterminant(det, pointer); This did not do the trick Dec 20, 2012 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.