No match for call to '(VecInt) (int, const int&)'

This is a discussion on No match for call to '(VecInt) (int, const int&)' within the C++ Programming forums, part of the General Programming Boards category; I'm trying to understand why I am getting the following errors given the code below. I'm trying to construct a ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Location
    Kansas City, MO
    Posts
    6

    Question No match for call to '(VecInt) (int, const int&)'

    I'm trying to understand why I am getting the following errors given the code below. I'm trying to construct a matrix and two vectors using various means but get the same error.

    Code:
    /*
     Begin NRldlmain.cpp
    */
    
    
    #include "nr3.h"
    #include "sparse.h"
    #include "NRldl.h"
    
    
    void init_Abc(const NRsparseMat &a, VecDoub_I &b, VecDoub_I &c, int M, int N, const int ptr_arr[], const int row_arr[], const double A_arr[])
    {
    NRsparseMatA;
    A.nrows = M;
    A.ncols = N;
    A.nvals = M*N;
     VecInt v, w;
    VecDouby;
     A.col_ptr(11,*ptr_arr);  *Error:No match for call to '(VecInt) (int, const int&)'
     A.row_ind = w(9,*row_arr);  *Error:No match for call to '(VecInt) (int, const int&)'
     A.val = y(9,*A_arr);  *Error:No match for call to '(VecDoub) (int, const double&)'
    }
    
    
    
    int main()  {
        
    DoubX_act[3]= {0.000000,0.957167,0.000000};
        Int my_Answer, N=3, M=3, k=1;
    Doub my_A_arr[9] = {0.814724,0.905792,0.126987,0.913376,0.632359,
    0.097540,0.278498,0.546882,0.957507}; // our A matrix in column-wise fashion
        const Int my_A_ptr_arr[11] = {0,1,2,3,4,5,6,7,8,9,10}; // [0...N+1]
        Int my_A_row_arr[9] = {0,1,2,0,1,2,0,1,2};
    Doub my_b_arr[3] = {0.874253,0.605273,0.093362}; // our contraint vector
    Doub my_c_arr[3] = {1.000000,1.000000,1.000000}; // our objective function coefficients
        
    NRsparseMatA;
    VecDoub_Ib, c;
    VecDoub_O x;
        
        init_Abc(A, b, c, M, N, my_A_ptr_arr, my_A_row_arr, my_A_arr);
        return my_Answer;
    }
    
    /*
     Begin sparse.h
    */
    
    struct NRsparseMat                            //sparse matrix data structure for compressed column storage
    {
        Int nrows;                            //number of rows
        Int ncols;                            //number of columns
        Int nvals;                            //maximum number of nonzeros
        VecInt col_ptr;                            //pointers to start of columns. length is ncols+1
        VecInt row_ind;                            //row indices of nonzeros
        VecDoub val;                            //array of nonzero values
    
    
        NRsparseMat();                            //default constructor
        NRsparseMat(Int m,Int n,Int nnvals);                //constructor. initializes vector to zero
        VecDoub ax(const VecDoub &x) const;                //multiply A by a vector x[0…ncols-1]
        VecDoub atx(const VecDoub &x) const;                //multiply A transpose by a vector x[0…nrows-1]
        NRsparseMat transpose() const;                    //form A transpose
    };
    
    
    typedef const NRvector<Int> VecInt_I;
    typedef NRvector<Int> VecInt, VecInt_O, VecInt_IO;
    
    
    typedef const NRvector<Doub> VecDoub_I;
    typedef NRvector<Doub> VecDoub, VecDoub_O, VecDoub_IO;
    
    
    #ifdef _USESTDVECTOR_
    #define NRvector vector
    #else
    
    
    template <class T>
    class NRvector {
    private:
        int nn;    // size of array. upper index is nn-1
        T *v;
    public:
        NRvector();
        explicit NRvector(int n);        // Zero-based array
        NRvector(int n, const T &a);    //initialize to constant value
        NRvector(int n, const T *a);    // Initialize to array
        NRvector(const NRvector &rhs);    // Copy constructor
        NRvector & operator=(const NRvector &rhs);    //assignment
        typedef T value_type; // make T available externally
        inline T & operator[](const int i);    //i'th element
        inline const T & operator[](const int i) const;
        inline int size() const;
        void resize(int newn); // resize (contents not preserved)
        void assign(int newn, const T &a); // resize and assign a constant value
        ~NRvector();
    };
    
    
    // NRvector definitions
    
    
    template <class T>
    NRvector<T>::NRvector() : nn(0), v(NULL) {}
    
    
    template <class T>
    NRvector<T>::NRvector(int n) : nn(n), v(n>0 ? new T[n] : NULL) {}
    
    
    template <class T>
    NRvector<T>::NRvector(int n, const T& a) : nn(n), v(n>0 ? new T[n] : NULL)
    {
        for(int i=0; i<n; i++) v[i] = a;
    }
    
    
    template <class T>
    NRvector<T>::NRvector(int n, const T *a) : nn(n), v(n>0 ? new T[n] : NULL)
    {
        for(int i=0; i<n; i++) v[i] = *a++;
    }
    

  2. #2
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    249
    Code:
    void init_Abc(const NRsparseMat &a, VecDoub_I &b, VecDoub_I &c, int M, int N, const int ptr_arr[], const int row_arr[], const double A_arr[])
    {
        NRsparseMatA;
        A.nrows = M;
        A.ncols = N;
        A.nvals = M*N;
        VecInt v, w;
        VecDouby;
        A.col_ptr(11,*ptr_arr);  *Error:No match for call to '(VecInt) (int, const int&)'
        A.row_ind = w(9,*row_arr);  *Error:No match for call to '(VecInt) (int, const int&)'
        A.val = y(9,*A_arr);  *Error:No match for call to '(VecDoub) (int, const double&)'
    }
    What type is A even of? Your function has a formal parameter named a (lower case), but that isn't used anywhere in the function! On the other hand, you are referencing a variable named A (upper case), which doesn't show up anywhere in the function's list of parameters.

  3. #3
    Registered User
    Join Date
    Jun 2012
    Location
    Kansas City, MO
    Posts
    6
    I see your point. I made the corresponding corrections but still get the error as shown below (sparse.h remains the same):

    Code:
    void init_Abc(NRsparseMat &a, VecDoub_I &b, VecDoub_I &c, Int M, Int N, const Int ptr_arr[], const Int row_arr[], const Doub A_arr[])
    {
    	a.nrows = M;
    	a.ncols = N;
    	a.nvals = M*N;
    	VecInt v, w;
    VecDouby;
    	a.col_ptr(11,*ptr_arr);  *Error:No match for call to '(VecInt) (int, const int&)'
    	a.row_ind = w(9,*row_arr);  *Error:No match for call to '(VecInt) (int, const int&)'
    	a.val = y(9,*A_arr);  *Error:No match for call to '(VecDoub) (int, const double&)'
    }
    
    int main()  {
    
    DoubX_act[3]= {0.000000,0.957167,0.000000};
     Int my_Answer, N=3, M=3, k=1;
    constDoub my_A_arr[9] = {0.814724,0.905792,0.126987,0.913376,0.632359,
    0.097540,0.278498,0.546882,0.957507}; // our A matrix in column-wise fashion
     const Int my_A_ptr_arr[11] = {0,1,2,3,4,5,6,7,8,9,10}; // [0...N+1]
     const Int my_A_row_arr[9] = {0,1,2,0,1,2,0,1,2};
    Doub my_b_arr[3] = {0.874253,0.605273,0.093362}; // our contraint vector
    Doub my_c_arr[3] = {1.000000,1.000000,1.000000}; // our objective function coefficients
    
    NRsparseMatA;
    VecDoub_Ib, c;
    VecDoub_O x;
    
     init_Abc(A, b, c, M, N, my_A_ptr_arr, my_A_row_arr, my_A_arr);
    }

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    This error is one of those that does what it says on the tin - it means that there is no matching function or constructor etc protoype that matches the one you are trying to call.

    Where this occurs with your own functions or classes then its failry easy to see where you went wrong and make the alteration. where the error references library material then you need to check the docs.

    The code below should produce that same message:

    Code:
    void foo(int var1, int var2)
    {
        //stuff
    }
    
    int main()
    {
      
      int v1 = 5;
    
      foo(v1);
    
      return 0;
    }
    Does you not get ' suggested candiadtes' in the compiler output also?
    Last edited by rogster001; 06-05-2012 at 02:57 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    Registered User
    Join Date
    Jun 2012
    Location
    Kansas City, MO
    Posts
    6
    Since row_ind is of type VecInt and w is typed the same way, wouldn't the call to the following bit of code be used?
    Code:
    typedef NRvector<Int> VecInt, VecInt_O, VecInt_IO;
    
    template <class T>
    NRvector<T>::NRvector(int n, const T *a) : nn(n), v(n>0 ? new T[n] : NULL)
    {
    	for(int i=0; i<n; i++) v[i] = *a++;
    }
    I guess I'm confused as to why it's not using this constructor.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    That constructor asks for an int and a pointer-to-const. The compiler tells you that the calling code is passing an int and a const-reference-to-int.
    Note the obvious difference, reference vs pointer.

    Do you simply mean to pass the pointer to the constructor instead of dereferencing it perhaps?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Jun 2012
    Location
    Kansas City, MO
    Posts
    6
    Thanks for the help iMalc. I believe what you mentioned in your last line cleared things up. Cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2011, 01:19 PM
  2. Replies: 3
    Last Post: 11-15-2009, 03:57 AM
  3. Replies: 1
    Last Post: 04-03-2009, 08:52 AM
  4. Replies: 7
    Last Post: 04-28-2008, 09:20 AM
  5. Replies: 3
    Last Post: 10-12-2006, 06:58 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21