A general theory of the problem of moments