c++ - pointers to object with external linkage to Nontype template parameters -


i tried following code.

template <int val> void printval() {     for(int i=0;i<val; i++){         cout << " value "<<i<<endl;     } } 

instantiation: printval<100>()

when use (std::string s ) non type template parameter, compiler shouted @ me following error

"class std::basic_str<char>' not valid type template non-type parameter. 

what know should use constant integral values only. not double.

question:

1) why should not use std::string, bothers ?

2) meaning of 'pointers objects external linkage can used'. can sample code it?

according 14.1/4,

a non-type template-parameter shall have 1 of following (optionally cv-qualified) types:

  • integral or enumeration type,
  • pointer object or pointer function,
  • lvalue reference object or lvalue reference function,
  • pointer member,
  • std::nullptr_t.

your std::string none of those.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -