Sep 9, 2013 at 5:23am UTC
Fixed
Last edited on Oct 3, 2013 at 8:45pm UTC
Sep 9, 2013 at 5:25am UTC
Fixed
Last edited on Oct 3, 2013 at 8:45pm UTC
Sep 9, 2013 at 5:28am UTC
a) why make it take a template if your going to "hard code" floats?
b) have you tried using *this?
Sep 9, 2013 at 6:03am UTC
Fixed
Last edited on Oct 3, 2013 at 8:45pm UTC
Sep 9, 2013 at 6:54am UTC
1 2 3 4 5 6
template <class DataType>
void Rectangle<DataType>::setLength(const float & length)
{
//side = length*2;
this -> length = length*2;
}
It is necessary to use
this-> here to specify the correct
length variable since you gave the parameter the same name as the member variable (which causes the parameter name to hide or "shadow" the data member with the same name.)
Or, if you prefer:
1 2 3 4 5
template <class DataType>
void Rectangle<DataType>::setLength(const float & len)
{
length = len*2;
}
But, I'm not sure sure why you're multiplying by 2 here. After all
length isn't named
doubleLength .
Last edited on Sep 9, 2013 at 6:57am UTC