You can use imenu-mode for that purpose. It comes shipped with emacs and most programming modes support it.
EDIT2: You could simply start it with this:
(add-hook 'prog-mode-hook (lambda () (imenu-add-to-menubar "Imenu")))
EDIT: I activate it by this code:
(defun my-try-to-add-imenu ()
(unless (my-is-buffer-file-temp)
(condition-case nil (imenu-add-to-menubar "Imenu") (error nil))))
(defun my-is-buffer-file-temp ()
"Returns t if buffer is temporary buffer. This is useful to disable hooks in org export."
(interactive)
(unless (boundp 'my-is-buffer-file-temp-var)
(make-local-variable 'my-is-buffer-file-temp-var)
(setq my-is-buffer-file-temp-var (my-is-buffer-file-temp-work)))
my-is-buffer-file-temp-var)
(add-hook 'prog-mode-hook 'my-try-to-add-imenu)
This only activates imenu-mode
if the current buffer has a corresponding file. I do this in order to avoid activation of some minor modes during org-export
.
The are more options available, which may require some customization to get them to work and which depend on the programming envirnment. Just to mention some: