Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Error C2555 with pointer to class with no template instantiation?

Reply
Thread Tools

Error C2555 with pointer to class with no template instantiation?

 
 
erictham115@gmail.com
Guest
Posts: n/a
 
      03-05-2007
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... ?

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-05-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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?

--
Ian Collins.
 
Reply With Quote
 
 
 
 
erictham115@gmail.com
Guest
Posts: n/a
 
      03-05-2007
On Mar 5, 1:50 pm, Ian Collins <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > 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?
>
> --
> Ian Collins.- Hide quoted text -
>
> - Show quoted text -


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

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      03-05-2007
(E-Mail Removed) wrote:
> On Mar 5, 1:50 pm, Ian Collins <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> 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?
>>
>> --
>> Ian Collins.- Hide quoted text -
>>
>> - Show quoted text -

>
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
Help getting to a derived class template given a pointer to a no-template base class chris.kemmerer@att.net C++ 7 09-28-2007 01:55 AM
Passing pointer to template function as argument to pointer to template function Vijai Kalyan C++ 4 11-08-2005 07:53 PM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments