Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type Initialization/Registration #163

Open
hs-apotell opened this issue Jan 30, 2021 · 0 comments
Open

Type Initialization/Registration #163

hs-apotell opened this issue Jan 30, 2021 · 0 comments

Comments

@hs-apotell
Copy link
Contributor

How to register types that are member of other classes that have property read/write calls? For instance -

class MyClass : public QObject
{
  CS_OBJECT(MyClass)

public:
  enum Color { Red, Green, Blue };

  CS_PROPERTY_READ(color, color)
  CS_PROPERTY_WRITE(color, setColor)

  Color color() const { return mColor; }
  void setColor(Color color) { mColor = color; }
};
CS_DECLARE_METATYPE(MyClass::Color)

This implementation fails to build. The error is something along this line -

error C2908: explicit specialization; 'const QString &cs_typeToName<R>(void)' has already been instantiated

The problem is that CS_PROPERTY_READ (and CS_PROPERTY_WRITE) both call cs_typeToName and so the compiler ends up adding the default implementation for Color. Adding an explicit declaration for the same type after the class declaration results in this error. Note that for classes that don't have these properties (or something else implicitly adding the default implementation), an explicit declaration is still required.

Is this understanding correct? Is there a better way to implement this where it is not left to the compiler to report when I should and when I shouldn't need an explicit declaration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant