Topic: should this template code compile?


Author: rmashlan@r2m.com (Robert Mashlan)
Date: 1996/08/22
Raw View
Given this code:

template<class T, int m, int n>
class matrix {
   // ...
   protected:
      T data[m][n];
};

template<class T,int m,int n,int p>
matrix<T,m,n> operator *(
   const matrix<T,m,p>& A,
   const matrix<T,p,n>& B
)
{
   matrix <T,m,n> R;
   // ...
   return R;
}

int main(void)
{
   matrix<double,3,3> A;
   matrix<double,3,2> B;
   matrix<double,3,2> C;
   C = A*B;  // Illegal structure operation?
   return 0;
}


Should this compile?   When I compile this with Borland C++ 5.0, it
gives me an illegal structure operation for the expression A*B, which
implies that the expression doesn't generate and use the function:

  matrix<double,3,2> operator *<double,3,2,3>(
   const matrix<double,3,3>&,
   const matrix<double,3,2>&
  )

from the template.

I get a similar error with the template function:

template<class T,int m, int n>
ostream& operator<< ( ostream&,  const matrix<T,m,n>& )

rm


---
Robert Mashlan  R2M Software  rmashlan@r2m.com
Internet Resources for Windows Developers http://www.r2m.com/windev/



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]