General discussion

Locked

Passing constants to functions

By miles.felton ·
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 <iostream>
template <class T>
class cS
{
public:
T fOutX(T&);
T fOutX(const T& iaX);
};
void main()
{
int iX = 125;
cS<int> csY;
csY.fOutX(31);
csY.fOutX(iX);
}
template <class T>
T cS<T>::fOutX(T& iaX)
{
std::cout << iaX << std::endl;
return iaX;
}
template <class T>
T cS<T>::fOutX(const T& iaX)
{
T iX = iaX;
return fOutX(iX);
}

If you see what I mean.

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Web Development Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums