C
cuneyt
Hi all:
I have defined the template
template<class T>
class CGroup
private:
int nSize;
public:
std::deque<T> c;
};
I would like to add a function that returns an element in the deque
with a given index (for other reasons, I chose not to use vector).
Below is my first attempt:
template<class T>
inline T& CGroup<T>::getElement( int nIndex ) const
{
if( (nIndex < 0) || (nIndex > c.size() ) ) {
std::cerr << "Index = " << nIndex << " out of range in
getElement()!" <<
std::endl;
exit(1);
}
return *(c.begin()+nIndex);
}
The compiler gave the error: return' : cannot convert from 'const
struct TFrame' to 'struct TFrame &'. How can I specify that the
reference to T that is being returned is a constant reference?
Thanks,
Cuneyt
I have defined the template
template<class T>
class CGroup
private:
int nSize;
public:
std::deque<T> c;
};
I would like to add a function that returns an element in the deque
with a given index (for other reasons, I chose not to use vector).
Below is my first attempt:
template<class T>
inline T& CGroup<T>::getElement( int nIndex ) const
{
if( (nIndex < 0) || (nIndex > c.size() ) ) {
std::cerr << "Index = " << nIndex << " out of range in
getElement()!" <<
std::endl;
exit(1);
}
return *(c.begin()+nIndex);
}
The compiler gave the error: return' : cannot convert from 'const
struct TFrame' to 'struct TFrame &'. How can I specify that the
reference to T that is being returned is a constant reference?
Thanks,
Cuneyt