Does DC comics allow actors to play heroes for both Marvel and DC related films?

I’ve often wondered if someone is cast as the main role in a Marvel or DC Comics film, are they then not allowed to portray another main hero. Take the guy who played Spider-Man in the Spider-Man films, or the guy who played Batman in the 2 new Batman projects. (Batman Begins/The Dark Knight) – how are those types of things worked out?