#include #include #include #include // Make sure boost::filesystem::path invokes code conversion #if defined(BOOST_WINDOWS) typedef std::string path_string; path_string foo_path = "foo.txt"; #else typedef std::wstring path_string; path_string foo_path = L"foo.txt"; #endif struct sink { path_string m_path; void foo() { boost::filesystem::path p(m_path); } }; struct core { boost::shared_ptr< sink > m_sink; ~core() { if (m_sink) m_sink->foo(); } static boost::shared_ptr< core > get_instance() { static boost::shared_ptr< core > instance; if (!instance) instance.reset(new core()); return instance; } }; int main() { boost::shared_ptr< core > c = core::get_instance(); c->m_sink.reset(new sink()); // Initialize the path locale after the core instance c->m_sink->m_path = boost::filesystem::path(foo_path).string< path_string >(); return 0; }