function, its argument can accept a string variable with and/or without const

How do we have a function with its argument accept a variable with and/or without const specifier, without double work or space creating full body size of its overload function? ie. just added very few lines of the solving codes
Last edited on
Huh?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

void foo ( const int &bar ) {
}

int main( ) {
  const int a = 1;
  int b = 3;
  foo(1);
  foo(a);
  foo(b);
}

foo doesn't care about the constness of whatever happens to be calling it.
foo is making a promise to NOT change whatever is passed in.


Topic archived. No new replies allowed.