Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

Is there any pattern that can combine overload and override? #208

@FlyinCow

Description

@FlyinCow

Say I have some c++ classes, each of them has a get and a set. They are abstractions of "attributes":

class Attribute{};

class IntAttribute: public Attribute{
public:
  int get(){return data;}
  void set(int value){data = value;}
private:
  int data;
};

class StringAttribute: public Attribute;

Naturally, different attribute types have different data types, therefore have different get and set (mostly T get() and void set(T)). I have to put them all together into a single container, so some polymorphism type is needed. But virtual functions can't help here because subclasses have different member function signatures.

Furthermore, to support arbitrary data type I have something like:

template<class T>
class TypedAttribute{
public:
  T get(){return data;}
  void set(T value){data = value;}
  template<class ...Args>
  void set(Args ...args){
    data = T{std::forward<Args>(args)...};
  }
private:
 T data;
};

Is there anything I can do with proxy to handle this situation? I can't figure out a way to dispatch get and set calls to subclasses. Currently I just dynamic convert a parent class into a subclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions