简体   繁体   中英

Access to different struct with same name

I'm trying to implement a workaround for boost versions that cause problems with scoped enums on linking in C++11 mode: See https://svn.boost.org/trac/boost/ticket/6779 and https://svn.boost.org/trac/boost/ticket/10038

The problem is simply: Most pre-distributed boost libs expose (namespaces stripped):
detail::copy_file(path const&, path const&, copy_option::enum_type, error_code*)
But C++11 compilation tries to find:
detail::copy_file(path const&, path const&, copy_option, error_code*)
due to the fact, that C++98 boost uses emulated scoped enums, instead of the C++11 ones.

I though I might be able to write an adapter for that put it into an own object file and link that into the program, but I failed with my naive approach:

#define copy_option native_copy_option__
#include <boost/filesystem/operations.hpp>
#undef copy_option

namespace boost {
namespace filesystem {

    struct copy_option{
        enum enum_type{none, fail_if_exists = none, overwrite_if_exists};
    };

namespace detail {

    void copy_file(const path& from, const path& to, copy_option::enum_type option, system::error_code* ec=0);

    using copy_option = native_copy_option__;
    void copy_file(const path& from, const path& to, copy_option option, system::error_code* ec)
    {
        copy_file(from, to, static_cast<boost::filesystem::copy_option::enum_type>(option), ec);
    }

}  // namespace detail
}  // namespace filesystem
}  // namespace boost

The problem is: I need to define a function with the C++11 enum in the signature but also declare a function with the C++98 enum which has the same name.

Is this somehow possible?

I think you should just write portable code.

Conditionally compiling "competing" variants of the code only solicits ODR violations and spurious ABI incompatibility issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM