Fixing compiler problems when using smart pointers in NetBeans

I like using NetBeans for C++ development within Linux environments.

Sometimes a gotcha can occur when trying to use the following declaration:

#include <memory>

You may wish use this in order to utilize smart pointers such as std::unique_ptr, leaving the user with a compilation error such as this:

error: ‘unique_ptr’ in namespace ‘std’ does not name a template type

It’s easy enough to overcome. Just make sure the appropriate compiler flag is set in NetBeans.

In NetBeans right-click your project and select Properties. Then select Additional Options field in Build > C++ Compiler:

NetBeans

In the Additional Options dialog just set the appropriate compilation flag such as -std=c++11:

NetBeans2

Click on OK and then Apply and then you’re away. You should now be able to use Standard Library smart pointers in NetBeans in Linux-based environments with no problems.

Leave a Reply