[英]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 我正在尝试为Boost版本实现一种变通方法,该版本会导致在C ++ 11模式下链接的作用域枚举出现问题:请参阅https://svn.boost.org/trac/boost/ticket/6779和https:// svn .boost.org / trac / boost / ticket / 10038
The problem is simply: Most pre-distributed boost libs expose (namespaces stripped): 问题很简单:大多数预分布的boost libs公开(去除了命名空间):
detail::copy_file(path const&, path const&, copy_option::enum_type, error_code*)
But C++11 compilation tries to find: 但是C ++ 11编译试图找到:
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. 由于这一事实,C ++ 98 boost使用了模拟范围的枚举,而不是C ++ 11的枚举。
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. 问题是:我需要在签名中定义带有C ++ 11枚举的函数,而且还需要声明具有相同名称的带有C ++ 98枚举的函数。
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. 有条件地编译该代码的“竞争”变体只会引起ODR违反和伪造的ABI不兼容问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.