Home template pointer parameter pack
Reply: 0

template pointer parameter pack

user6351
1#
user6351 Published in September 21, 2018, 8:03 am

Why a template function with a template parameter pack of pointers cannot be instantiated with offsets of the same pointer?

I mean: given this short code why must I comment out the last two lines?

template <int * ... pt> void f() {}

int n[] = {1, 2, 3};
int m = n[1];

int main()
{
    f<n>();  // this is accepted
    f<n, &m>();  // this is accepted too
    //f<n, n+1>(); // this is not.
    //f<n, &n[1]>(); // this isn't accepted neither
}

Doesn't n+1 represent the same address as &m ? Or there is a difference in the linkage? Or what else?

share|improve this question
  • m is its own variable; &m has no relation to n. – chris Feb 12 at 18:31
  • Try int * p = &n[0]; f<p>(); for a nice explanation. – Richard Critten Feb 12 at 18:33

2 Answers 2

active oldest votes
up vote 3 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.310232 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO