Mail Archives: djgpp/1997/04/22/18:45:33
Hi ye'all,
consider the following:
// template for a N-dimensional vector type
// with: D - the number of dimensions
// T - the type of elements
template< const int D, class T>
class part_of_vector_template {
protected:
T e[ D];
public:
part_of_vector_template & operator *=( double arg_d) {
for ( register int i =0; i < D; i++)
e[ i] *= arg_d; // **warning**
return *this;
};
part_of_vector_template
operator +( register const part_of_vector_template & arg_v) const
return t; { // **error**
// nifty GNU C++ extension
----^^^^^^^^
for ( register int i =0; i < D; i++)
t.e[ i] = e[ i] + arg_v.e[ i];
};
};
The first operator ( *=, that is) generates a warning when:
class part_of_vector_template<whatever, int>;
warning:
storing double in int or something like that, writing:
e[ i] = (int)(e[ i] * arg_d);
solves it, but hey what's that nifty *= operator for ??
The second operator ( +, never would've guessed it right) generates an
error,
for which I don't know the solution.
writing:
...
part_of_vector_template
operator +( register const part_of_vector_template & arg_v) const {
part_of_vector_template t;
...
return t;
};
...
would ofcourse work, but with much less efficent code. Can this named
return C++ extension only be applied on regular functions, and not on
member-functions or is it the template aspect of the whole thingy that
fuckes it up ???
Has anyone got some useful to say about this (most iritating) problem..
Thnx,
Peter
- Raw text -