No, the functon that code is inside of is neither in a class or namespace.
Can you post enough code to demonstrate the whole problem? Like, the class/namespace, and two blocks of code that you want to duplicate (are duplicates of each other).
From what you've posted I don't see the problem.
I'll try to explain it a little better.
I have my main program. I have my main loop in my main program. My main loop handles timing and input and puts that data in globals so functions can access it. And it calls a function, protonpack():
/* ---
Main loop - Executes continuously while the system is powered.
--- */
void loop() {
// Constants:
// Statics: (These are initialized once and their value is maintained on each subsequent loop.)
// Temporary variables:
// Timing:
lastTime = time; // Store start time of last update.
time = millis(); // Get current system time.
timeDelta = time - lastTime; // Calculate how long last update took, in milliseconds.
timeDeltaSec = float(timeDelta) / 1000.0; // Convert last update period into seconds.
//Serial1.println(timeDelta);
// Read all switch states:
readIOPorts();
// This is where all the magic happens:
protonpack();
// Update LEDs:
updateLEDs();
// Play any queued sound effects once the current sound effect ends:
updateSound();
// Calculate time left in this frame and delay if needed.
// timeDelta = millis()-time;
// if (timeDelta < 16) { delay(16-timeDelta); }
}
That function contains all the code that makes the board do all this:
And the contents of that function are basically a large switch statement that performs whatever actions are needed based on the current state.
But let's say I want to reconfigure the board to do this:
In that case, I would like to replace the call to protonpack() with a call to ghosttrap() and not have to mess with any of the code in my main program. And sticking a bunch of globals in my main program which are specific to protonpack() is a big no-no, because then I'm altering my main program and I, or whomever else is modifying the code, might accidentally delete something they shouldn't, or do something else to break everything.
I'm basically trying to keep the code that drives everything behind the scenes, and everything protonpack() does, completely separate from eachother.
And it seems like sticking it in a namespace or class might be the best solution, although I am not sure if the IDE will allow me to put that code in a tab by itself rather than sticking it in my main program where I don't want it.