I had the same problems in Ubuntu 6.10 and ns-2-31. I had to compile with gcc and g++ 4.0 instead of 4.1 (default in my distro).
There are a couple of urls documenting this and how to install ns in ubuntu. http://thesandeep.wordpress.com/2006/12/02/installing-ns2-on-ubuntu-dapper-lts/ http://nsnam.isi.edu/nsnam/index.php/Troubleshooting#ns-2.30.2Fns-2.31_do_not_build_with_gcc.2Fg.2B.2B_4.1 -as