Моделирование чистой виртуальной функции элемента шаблона с помощью boost.typeerasureC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Моделирование чистой виртуальной функции элемента шаблона с помощью boost.typeerasure

Сообщение Anonymous »

Документация для Boost.TypeerAsure включает в себя пример «форматирование полиморфного диапазона», который имитирует концепцию «чисто виртуальной функции члена шаблона». Я могу скомпилировать и запустить этот пример кода, который определяет иерархию класса, которая позволяет отформатировать последовательность несколькими различными способами. Я хотел бы привести это к гораздо более простому примеру, который просто принимает значение и отправляет его на std :: out. Вот моя наивная попытка: < /p>

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

#include 
#include 
#include 
#include 
#include 
#include 

using namespace boost::type_erasure;

struct _x : placeholder {};

class abstract_printer2 {
public:
template
void print(X x) const {
tuple args(x);
do_print(get(args));
}
virtual ~abstract_printer2() {}
protected:
typedef boost::mpl::vector<
ostreamable
> requirements;
typedef boost::type_erasure::any x_type;
virtual void do_print(x_type x) const = 0;
};

class separator_printer2 : public abstract_printer2 {
protected:
virtual void do_print(x_type x) const {
std::cout 
Build started at 14:02...
1>------ Build started: Project: test, Configuration: Debug x64 ------
1>test.cpp
1>C:\bob\projects\test\test.cpp(17,17): error C2280: 'boost::type_erasure::any::any(const boost::type_erasure::any &)': attempting to reference a deleted function
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(1928,1):
1>compiler has generated 'boost::type_erasure::any::any' here
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(1928,1):
1>'boost::type_erasure::any::any(const boost::type_erasure::any &)': function was implicitly deleted because a base class invokes a deleted or inaccessible function 'boost::type_erasure::any_constructor_control::any_constructor_control(const boost::type_erasure::any_constructor_control &)'
1>        with
1>        [
1>            Concept=abstract_printer2::requirements,
1>            T=_x
1>        ]
1>C:\bob\projects\boost\boost\type_erasure\any.hpp(376,5):
1>'boost::type_erasure::any_constructor_control::any_constructor_control(const boost::type_erasure::any_constructor_control &)': function was explicitly deleted
1>        with
1>        [
1>            Concept=abstract_printer2::requirements,
1>            T=_x
1>        ]
1>C:\bob\projects\test\test.cpp(17,17):
1>the template instantiation context (the oldest one first) is
1>  C:\bob\projects\test\test.06.factory\test.cpp(38,7):
1>  see reference to function template instantiation 'void abstract_printer2::print(X) const' being compiled
1>        with
1>        [
1>            X=int
1>        ]
1>Done building project "test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 14:02 and took 01.517 seconds ==========
Что я делаю не так?

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

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

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

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

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

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

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