Error C2555 with pointer to class with no template instantiation?

E

erictham115

Error C2555

c:\C++ projects\stat1\stdmatrix_adapt.h(41) : error C2555:
'std_tools::Matrix_adapter<T>::at': overriding virtual function return
type differs and is not covariant from 'ple::imtx_impl<T>::at'

//in my program: the derived class
template <class T>
class Matrix_adapter : public ple::imtx_impl<T> {
protected:
Matrix* m_;
public:
virtual const T& at(mtx_size i0, mtx_size i1) const //mtx_size -->
unsigned int
{return m_->at(i0, i1);}
}
// the base class
template <class T>
class imtx_impl : public imtx<T> {
virtual const T& at(mtx_size i0, mtx_size i1) const=0;

/*Notice Matrix_adapter.at returns a pointer to another class Matrix
m_
The problem arises as this class Matrix has no template instantiation
and i set the virtual function at return as double, the same as T */

class Matrix : public GeneralMatrix
public:{
const double& at(unsigned int pos0, unsigned int pos1) const { return
v_.at(c_(pos0, pos1)); }
}

// However in my main program initiating T as double in the derived
class still gives the error C2555.

Matrix_adapter <double> matx;

Am at loss what to do now.. any people care to help... ?
 
I

Ian Collins

Error C2555

c:\C++ projects\stat1\stdmatrix_adapt.h(41) : error C2555:
'std_tools::Matrix_adapter<T>::at': overriding virtual function return
type differs and is not covariant from 'ple::imtx_impl<T>::at'

//in my program: the derived class
template <class T>
class Matrix_adapter : public ple::imtx_impl<T> {
protected:
Matrix* m_;
public:
virtual const T& at(mtx_size i0, mtx_size i1) const //mtx_size -->
unsigned int
{return m_->at(i0, i1);}
}
// the base class
template <class T>
class imtx_impl : public imtx<T> {
virtual const T& at(mtx_size i0, mtx_size i1) const=0;

/*Notice Matrix_adapter.at returns a pointer to another class Matrix
m_
The problem arises as this class Matrix has no template instantiation
and i set the virtual function at return as double, the same as T */

class Matrix : public GeneralMatrix
public:{
const double& at(unsigned int pos0, unsigned int pos1) const { return
v_.at(c_(pos0, pos1)); }
}

// However in my main program initiating T as double in the derived
class still gives the error C2555.

Matrix_adapter <double> matx;

Am at loss what to do now.. any people care to help... ?
The code fragments as posted look OK, can you reproduce the problem with
a self contained example?
 
E

erictham115

The code fragments as posted look OK, can you reproduce the problem with
a self contained example?

Ya i thought the derived and base classes look ok. Except that the
class that the pointer points is not a template class.
 
V

Victor Bazarov

Ya i thought the derived and base classes look ok. Except that the
class that the pointer points is not a template class.

There is no such think in C++ as "template class". There is a class
template and there is a class generated from a template (a template
instantiation). Please adjust your statement and explain what (or
which) you mean.

You didn't post what 'imtx' template looked like, you didn't post
any code that uses your template (which would show instantiation of it
and the template arguements). Please consult with FAQ 5.8 for further
clarification.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top