templated class member function declaration ???

OK, I have the following kind of self-explaining code (all irrelevant stuff is omitted)

lsq_neq.h:
1
2
3
4
5
6
7
8
9
10
11
12
#include<boost/numeric/mtl/mtl.hpp>

template <typename T>
class lsq_neq
{
	typedef typename mtl::matrix::dense2D<T> matrix;
	typedef typename mtl::vector::dense_vector<T> vector;
public:
	lsq_neq(int n, int m, int m2);
	~lsq_neq();
	vector nnls(const matrix &E, const vector &f);
};

lsq_neq.cpp
1
2
3
4
5
6
7
8
9
#include "lsq_neq.h"

using namespace mtl;
template<typename T>
lsq_neq<T>::vector lsq_neq<T>::nnls(const lsq_neq<T>::matrix &E, const lsq_neq<T>::vector &f)
{
	lsq_neq<T>::vector x(size(f));
	return(x);
}


And it does not compile with
error: expected constructor, destructor, or type conversion before 'lsq_neq'
What am I doing wrong?
You need typename there as well.

But I would strongly advise against using "vector" as the name of your typedef.
You need typename there as well
sorry, where? OK there were not so many possibilities so I found it out
1
2
template<typename T>
typename lsq_neq<T>::vector lsq_neq<T>::nnls(const typename lsq_neq<T>::matrix &E, const typename lsq_neq<T>::vector &f)
but it is ugly! Why? It would be nice if I did not have to use those templated patterns in definition part at all.

But I would strongly advise against using "vector" as the name of your typedef
because of std::vector?
Last edited on
Your declaration is unecessarily wordy. You can shorten it to:

1
2
template< typename T >
typename lsq_neq<T>::vector lsq_neq<T>::nnls( const matrix& E, const vector& f )


Because when the compiler parses the parameters, it is already in the scope of lsq_neq<T>.

And yes, because of std::vector.
Shouldn't that definition also be in the header file when using the inclusion model to avoid violating the one definition rule?

EDIT: Actually, it might not have anything to do with the ODR--I might have myself all mixed up again... :P
Last edited on
Thank you. I got it.
Topic archived. No new replies allowed.