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

Implement template flag to attribute<> to defer object creation #148

Open
concancon opened this issue May 7, 2020 · 2 comments
Open

Implement template flag to attribute<> to defer object creation #148

concancon opened this issue May 7, 2020 · 2 comments

Comments

@concancon
Copy link

Defer the initialization of a member object to allow for user parametrization before creation.

@jeremybernstein
Copy link

This isn't generally possible in C++ (@tap may have completely rewritten the construction process, though, so I might be wrong in this case). But you can make the member a pointer (or unique_ptr) and allocate/initialize it in the constructor, as per the docs wrt the m_beat_generator member variable. Or make the default constructor of your member object do nothing (maybe set a flag 'valid' to false), and then add a member function to initialize the object (which would set the flag 'valid' to true) and check for validity before using the object? Something like that. But I think the pointer initialization is the most idiomatic here.

@tap
Copy link
Contributor

tap commented May 7, 2020

Correct. The attribute<> class will still have it's constructor called when the Min class is initialized. I'm imagining that in this case that the assignment of the value internally to the attribute will not happen at that time, however.

There are questions though... Does the object then get initialized when the "loadbang" message is sent? Or not at all? Or... ?

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

No branches or pull requests

4 participants