Discussion Locked

Passing constants to functions

0 helpful
0 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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.

0 replies

No replies were posted before this discussion closed.

This discussion is closed to new replies.