0

I'm trying to write something like this :

template <typename type,int p,int q = 1> struct const4array
    {
    static const type value [] = { type(p)/type(q) , type(p)/type(q) , type(p)/type(q) , type(1) } ;
    };

double xx [] = { 0.5 , 0.5 , 0.5 , 1 } ;
double yy [] = const4array<double,1,2>::value ; // I would like to have : xx == yy

I think this code is easy to understand for a human developer, but apparently not for the compiler (it returns many errors).

Is it possible to do what I want, and if it is, how to do it properly? (I found many other questions that looks like this one, but not close enough to match mine).

Thanks in advance!

1
  • I think, it is broken by the same reason why double zz[] = xx; doesn't work as well. I tried on godbolt Commented Jul 7, 2019 at 12:43

1 Answer 1

1

Plain C-style arrays can only be initialized using {} syntax, they can't be copy-initialized from other arrays. You can however use objects emulating or wrapping arrays (like std::array) as those can be copied and used for initialization.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.