Как применить Boost.TypeerAsure к значению типа "shared_ptr &"?C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Как применить Boost.TypeerAsure к значению типа "shared_ptr &"?

Сообщение Anonymous »

Мой проблемный домен состоит из ассортимента иерархий классов без общего базового класса. Во время инициализации я экземпляры бетонные экземпляры. Я хочу хранить их в гетерогенном контейнере. Позже я хочу получить объект и вызвать его интерфейс базового класса, не зная его производного типа. Если по ошибке я вызываю интерфейс, который объект не поддерживает, я ожидаю получить ошибку времени выполнения. Классы обертки наследуют от чисто виртуального базового класса, который использует стирание типа усиления для делегирования типа (

Код: Выделить всё

shared_ptr
) для полученных классов обертки. Я могу поместить эти объекты обертки в контейнер. Вот моя наивная попытка реализовать это: < /p>

Код: Выделить всё

#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 ==========
Что я делаю не так?

Подробнее здесь: https://stackoverflow.com/questions/794 ... hared-ptrt
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

&"?" class="inputbox autowidth" />
&"?" />
Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»