Any way to pass 'nothing' to a function member defined 'by ref'

I have this function ( depending on some criteria id will have 1 or 2 )
1
2
3
4
my_function(int &id) 
{ id=1  
....
id=2 }


Ok, sometimes I want to call the function, but I have no interest in knowing the id value. How can I call the function ?
( I dont want to declare a garbage var ...)
Either return the id or use a pointer instead of a reference.
Provide a parameterless overload that calls this one with a local.

But if you have a function that does something and returns something, and the thing it does is useful with or without the return value, it's a sign that the function is bloated and should be split up into smaller functions.
closed account (1vRz3TCk)
You could do something along the lines of:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

using namespace std;

static int dummy = 0;

void my_function(int &id = dummy) 
{ 
    id = 1;
}

int main()
{
	my_function();

	return 0;
}
No offense, but I like
1
2
3
4
5
6
7
8
9
10
void my_function(int &id) 
{ 
    id = 1;
}

void my_function()
{
    int id;
    my_function(id);
}


better. I'd still like to know what the actual example here is though, as I am pretty sure that the better solution would probably be refactoring.
closed account (1vRz3TCk)
I reserve opinion as to what I like as a solution as the full details of the problem domain are not available to me; I only offer a posable solution for the OPs consideration.
_____
P.S. I take no offense :0)
Topic archived. No new replies allowed.