Is there any simpler way to achieve Type erasure with functions that return say an instance of the type. For example, one using some kind of type-erasure, there are other models with type info, but got stuck because there is no easy way to get full type name for ‘b’ boolean, ‘i’ int. Remember the end goal is using this return values to declare types or verify type declarations for member function pointers with little use of templates. Because the project should be simple to use, not cluttered with template arguments, because with templates, if a class template takes 3 type parameters and instances of this class are contained as data members in another class, imagine the mess it will have in the definition and declaration of the container object. So I am trying something like the following as in wikibooks example, and look the missing parts from the code below. Any simple way to get this working? Thank you in advance!
class object_t {
public:
template<typename T>
object_t(T x) : self_(std::make_shared<model<T>>(std::move(x))) {}
friend ??? get() {
x.self_->get(); //This should finally call the derived class get()
}
private:
struct concept_t {
virtual ~concept_t() = default;
virtual ??? get() const = 0;
};
template<typename T>
struct model final : concept_t {
model(T x) : data_(std::move(x)) {}
T get() const override { //Here is what I am interested in getting at
return data_;
}
T data_;
};
std::shared_ptr<const concept_t>self_;
};
mast is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.