c++11 - c++ send arguments to union (variable union) -


well cant find how this, variable union params, basic idea, (writed function)

ex1

union (int le) {   int i[le];   float f[le]; }; 

ex2

union {   int le;   int i[le];   float f[le]; }; 

obs don't works d: maybe way use internal variable set lenght don't works too. thx.

no, not possible: le need known @ compile-time.

one solution use templated union:

template <int n> union {     int i[n];     float f[n]; }; 

n, of course, compile-time evaluable.

another solution arguably more succinct

 typedef std::vector<std::pair<int, float>> some; 

or similar solution based on std::array.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -