Passing constants to functions - TechRepublic
General discussion
April 7, 2003 at 08:25 PM
miles.felton

Passing constants to functions

by miles.felton . Updated 23 years, 3 months ago

The topic ‘USE NON-CONSTANT LITERALS TO PASS CONSTANT REFERENCES, PART 1’ is interesting. But don’t forget that when you are writing your own library that you can make it so that your callers don’t have do that. Here is an example:-
#include
template
class cS
{
public:
T fOutX(T&);
T fOutX(const T& iaX);
};
void main()
{
int iX = 125;
cS csY;
csY.fOutX(31);
csY.fOutX(iX);
}
template
T cS::fOutX(T& iaX)
{
std::cout << iaX << std::endl; return iaX; } template
T cS::fOutX(const T& iaX)
{
T iX = iaX;
return fOutX(iX);
}

If you see what I mean.

This discussion is locked

All Comments