Last question first: overloading concept applies to Solidity but, as for other programming languages supporting overloading functions, i.e. C++, they are not related to each other in any way.
Functions with same name but different parameters are identified by different signatures, so they are actually different functions. If ContractA
defines doSomething()
, ContractB
defines doSomething(string myString)
, and ContractB
inherits from ContractA
, final ContractB will have two valid functions that user can call: doSomething()
and doSomething(string myString)
. Visibility also is part of the signature, but it can't be overloaded.
Main question now. From the outside of the contract, you cannot call a base function that has been overridden. This is because what you are calling from the outside is the final contract implementation, no matter how you define the interface on the client to call it.
If you defines
contract EvilDoer{
function doSomethingEvil{
A contractB = A(addressOfdeployedB);
contractB.doSomething();
}
}
You are simply defining another - and more restrictive - pointer to ContractB
and to its implementation of doSomething()
. And its implementation is the last one.
But hei, I know default function visibility is public, what if I define explicitly the base function in ContractA
as external
?
Not much, because you cannot override a function changing its extended signature. Visibility and return parameters are part of the extended function signature, so the compiler throws an error:
TypeError: Override changes extended function signature.
If you want to compile you need to use the same external
modifier also in the ContractB
function, and then again, the last implementation of function wins in any case.
Please note that changing visibility or return parameters it's not considered an overload neither, because functions are identified by signatures, contracts can't have two functions with the same signature and different extended attributes.
For more information about inheritance topics you can read the official documentation, in particular the information about the super
keyword and the final inheritance graph of the contract.
I'm having a bit difficulties following your writing, so I'll make this a bit more generalized.
If you are the one who released the token then you have decided how the tokens can be transferred. Most likely you as the contract owner have full power to transfer any amount of tokens to whoever you wish, or maybe even remove tokens from someone (yes, tokens can be removed as they only exist within the same contract, they are never actually 'sent' anywhere).
So if you have full power over the tokens you can just do whatever you want with them - hold some in any sort of escrow for example if your contract supports such functionality.
If you did not create the token contract (but it was created by someone else) you can act as an escrow and get the tokens transferred to your account. When the escrow service is no longer needed, you can either authorize (approve
function in ERC20) the transfer back to someone or directly transfer them with the transfer
function.
Best Answer
Short answer is Contracts are full participants, so when someone sends funds, then the contract has the funds.
The contract can then decide if/when to send the funds and to whom. In your use-case, it implies keeping track of who is owed funds. You would do that as funds are received.
Very sketchy example to help illustrate the flow.
Here it is in Remix. 10 deposited, then 9 withdrawn. Running totals and client balances.
Hope it helps.