Мой проблемный домен состоит из ассортимента иерархий классов без общего базового класса. Во время инициализации я экземпляры бетонные экземпляры. Я хочу хранить их в гетерогенном контейнере. Позже я хочу получить объект и вызвать его интерфейс базового класса, не зная его производного типа. Если по ошибке я вызываю интерфейс, который объект не поддерживает, я ожидаю получить ошибку времени выполнения. Классы обертки наследуют от чисто виртуального базового класса, который использует стирание типа усиления для делегирования типа (
#include
#include
#include
#include
#include
#include
#include
#include
using namespace boost::type_erasure;
// PROBLEM DOMAIN - disparate hierarchies of classes:
struct Base {
virtual ~Base() {}
virtual void f() = 0;
};
struct Derived : Base {
void f() override {
std::cout get(b);
if (b) b->f();
}
< /code>
Этот код компилируется и работает под Visual Studio 2022, но он не ведет себя так, как я желаю, потому что я прокомментировал эту строку: < /p>
//x = d;
< /code>
Когда я расстроен эту строку, компиляция не удается со следующей ошибкой: < /p>
Build started at 11:38...
1>------ Build started: Project: test, Configuration: Debug x64 ------
1>test.cpp
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9): error C2672: 'boost::type_erasure::any::_boost_type_erasure_assign_impl': no matching overloaded function found
1>(compiling source file 'test.cpp')
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2321,10):
1>could be 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const void *,boost::mpl::true_)'
1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2293,14):
1> 'initializing': cannot convert from 'boost::mpl::and_' to 'boost::mpl::true_'
1> with
1> [
1> Concept=wrapper_base::requirements,
1> Other=std::shared_ptr &
1> ]
1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2293,14):
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2307,10):
1>or 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::true_)'
1> with
1> [
1> T=_x
1> ]
1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9):
1> 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::true_)': could not deduce template argument for 'const boost::type_erasure::assignable *' from 'void *'
1> with
1> [
1> T=_x
1> ]
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2298,10):
1>or 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::false_)'
1> with
1> [
1> T=_x
1> ]
1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9):
1> 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::false_)': could not deduce template argument for 'const boost::type_erasure::assignable *' from 'void *'
1> with
1> [
1> T=_x
1> ]
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9):
1>the template instantiation context (the oldest one first) is
1> C:\bob\projects\test\test.cpp(54,11):
1> see reference to function template instantiation 'boost::type_erasure::any &boost::type_erasure::any::operator =(U)' being compiled
1> with
1> [
1> U=std::shared_ptr &
1> ]
1> C:\bob\projects\test\test.cpp(54,11):
1> see the first reference to 'boost::type_erasure::any::operator =' in 'wrapper_derived::do_get'
1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2234,9):
1> see reference to function template instantiation 'void boost::type_erasure::any::_boost_type_erasure_resolve_assign(Other)' being compiled
1> with
1> [
1> Other=std::shared_ptr &
1> ]
1>Done building project "test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 11:38 and took 01.500 seconds ==========
Мой проблемный домен состоит из ассортимента иерархий классов без общего базового класса. Во время инициализации я экземпляры бетонные экземпляры. Я хочу хранить их в гетерогенном контейнере. Позже я хочу получить объект и вызвать его интерфейс базового класса, не зная его производного типа. Если по ошибке я вызываю интерфейс, который объект не поддерживает, я ожидаю получить ошибку времени выполнения. Классы обертки наследуют от чисто виртуального базового класса, который использует стирание типа усиления для делегирования типа ([code]shared_ptr[/code]) для полученных классов обертки. Я могу поместить эти объекты обертки в контейнер. Вот моя наивная попытка реализовать это: < /p> [code]#include #include #include #include #include #include #include #include
using namespace boost::type_erasure;
// PROBLEM DOMAIN - disparate hierarchies of classes: struct Base { virtual ~Base() {} virtual void f() = 0; };
struct Derived : Base { void f() override { std::cout get(b); if (b) b->f(); } < /code> Этот код компилируется и работает под Visual Studio 2022, но он не ведет себя так, как я желаю, потому что я прокомментировал эту строку: < /p> //x = d; < /code> Когда я расстроен эту строку, компиляция не удается со следующей ошибкой: < /p> Build started at 11:38... 1>------ Build started: Project: test, Configuration: Debug x64 ------ 1>test.cpp 1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9): error C2672: 'boost::type_erasure::any::_boost_type_erasure_assign_impl': no matching overloaded function found 1>(compiling source file 'test.cpp') 1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2321,10): 1>could be 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const void *,boost::mpl::true_)' 1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2293,14): 1> 'initializing': cannot convert from 'boost::mpl::and_' to 'boost::mpl::true_' 1> with 1> [ 1> Concept=wrapper_base::requirements, 1> Other=std::shared_ptr & 1> ] 1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2293,14): 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called 1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2307,10): 1>or 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::true_)' 1> with 1> [ 1> T=_x 1> ] 1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9): 1> 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::true_)': could not deduce template argument for 'const boost::type_erasure::assignable *' from 'void *' 1> with 1> [ 1> T=_x 1> ] 1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2298,10): 1>or 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::false_)' 1> with 1> [ 1> T=_x 1> ] 1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9): 1> 'void boost::type_erasure::any::_boost_type_erasure_assign_impl(Other &&,const boost::type_erasure::assignable *,boost::mpl::false_)': could not deduce template argument for 'const boost::type_erasure::assignable *' from 'void *' 1> with 1> [ 1> T=_x 1> ] 1>C:\bob\projects\boost\boost\type_erasure\any.hpp(2270,9): 1>the template instantiation context (the oldest one first) is 1> C:\bob\projects\test\test.cpp(54,11): 1> see reference to function template instantiation 'boost::type_erasure::any &boost::type_erasure::any::operator =(U)' being compiled 1> with 1> [ 1> U=std::shared_ptr & 1> ] 1> C:\bob\projects\test\test.cpp(54,11): 1> see the first reference to 'boost::type_erasure::any::operator =' in 'wrapper_derived::do_get' 1> C:\bob\projects\boost\boost\type_erasure\any.hpp(2234,9): 1> see reference to function template instantiation 'void boost::type_erasure::any::_boost_type_erasure_resolve_assign(Other)' being compiled 1> with 1> [ 1> Other=std::shared_ptr & 1> ] 1>Done building project "test.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 11:38 and took 01.500 seconds ========== [/code] Что я делаю не так?
Вот код
Это функция, которая вставляет узел после указанного местоположения. Здесь у нас есть узел temp и ptr. Узел Temp будет хранить узел, после которого необходимо вставить новый узел, а узел ptr хранит данные нового узла.
здесь после...
Вот код
Это функция, которая вставляет узел после указанного местоположения. Здесь у нас есть узел temp и ptr. Узел Temp будет хранить узел, после которого необходимо вставить новый узел, а узел ptr хранит данные нового узла.
здесь после...
Документация для Boost.TypeerAsure включает в себя пример «форматирование полиморфного диапазона», который имитирует концепцию «чисто виртуальной функции члена шаблона». Я могу скомпилировать и запустить этот пример кода, который определяет иерархию...
Документация для Boost.TypeerAsure включает в себя пример «форматирование полиморфного диапазона», который имитирует концепцию «чисто виртуальной функции члена шаблона». Я могу скомпилировать и запустить этот пример кода, который определяет иерархию...
У меня есть реализация:
Получение heap-use-after-free с трассировкой, указывающей на
#0 0x102b82868 in int std::__1::__cxx_atomic_fetch_sub (std::__1::__cxx_atomic_base_impl*, int, std::__1::memory_order) cxx_atomic_impl.h:464