DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Mismatched Types?

  1. #1
    Join Date
    Oct 2003
    Posts
    3

    Mismatched Types?

    I keep getting an error when trying to use a matrix class someone else wrote about 10 years ago in VC++ 6.0:

    Optimizer.cpp:48: error: no matching function for call to 'matrix<double>::matrix(matrix<double>)'
    Matrix.h:16: note: candidates are: matrix<T>::matrix(matrix<T>&) [with T = double]

    The following is the code with most of the irrelevant stuff removed.

    The matrix function definition looks like this:
    Code:
    template<class T>
    matrix<T>::matrix(matrix<T> &x)
    {
    	}

    Matrix also has this overloaded operator:
    Code:
    template<class T>
    matrix<T> &matrix<T>::operator=(matrix<T> &x)
    {
    }

    The definition of testPredictor looks like this:
    Code:
    matrix<double> Predictor::testPredictor(matrix<double> _testX)
    {
    	matrix<double> predictY;
    	return predictY;
    }
    The actual line of code where the error trips is:
    Code:
    matrix<double> trainPredictY = testPredictor(trainX);
    where trainX is defined in the header as:
    Code:
    matrix<double> trainX;
    Making it
    Code:
    matrix<T>::matrix(const matrix<T> &x)
    gives me this error:
    Matrix.cpp:47: error: passing 'const matrix<double>' as 'this' argument of 'vect<T> matrix<T>::get_row(int) [with T = double]' discards qualifiers

    Making it
    Code:
    matrix<double> trainPredictY( testPredictor(trainX) );
    gives me this error:
    Optimizer.cpp:48: error: no matching function for call to 'matrix<double>::matrix(matrix<double>)'
    Matrix.h:16: note: candidates are: matrix<T>::matrix(matrix<T>&) [with T = double]
    Matrix.h:15: note: matrix<T>::matrix(int, int) [with T = double]
    Matrix.h:14: note: matrix<T>::matrix() [with T = double]


    Any ideas? Thanks.

  2. #2
    Join Date
    Oct 2007
    Posts
    369
    Change your assignment operator to take a const matrix<T> &x. When performing an assignment, the right-hand side shouldn't change. Further, go through each routine and for those not changing the object, make the routine "const". For example, a routine named "get_row" shouldn't be changing the state of the object, so declare it const.

Similar Threads

  1. Thoughts on Data Types
    By marsigme in forum C++
    Replies: 5
    Last Post: 09-23-2007, 05:02 PM
  2. Replies: 0
    Last Post: 05-18-2005, 10:40 AM
  3. Defining data types
    By denis_v in forum Database
    Replies: 6
    Last Post: 05-06-2005, 12:08 PM
  4. What is the UDT?
    By Tahui in forum VB Classic
    Replies: 2
    Last Post: 11-22-2000, 11:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center