How to install a specific version of g++?
Download the g++-4.1 version from here. g++-4.1 is not available in the recent Ubuntu repositories. So you need to download the package from the link provided.
Install/compile the download package alongside with the current version of g++.
Then use update-alternatives
to switch version
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.3 10
Change the default version by choosing the appropriate version:
sudo update-alternatives --config g++