Dear All,
I'm trying to go thru the non-type template-parameter rules in draft c+
+ standard. Here is one example which I tried to execute.
#include<iostream>
template <int *p> class MyArr
{
public:
MyArr();
};
MyArr::my_print()
{
std::cout<<"Hello World\n";
}
main ()
{
int a[100];
MyArr<a> b_arr;
b_arr.my_print();
system ("pause");
}
As per the standard it says that - A non-type template-parameter of
type "array of T" is adjusted to be of type "pointer to T".
I'm getting below error while trying to compile the above program. Can
anyone please explain me the compiler errors in this and why they are
coming?
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:8: error:
`template<int*p> class MyArr' used without template parameters
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:9: error: ISO C++ forbids
declaration of `my_print' with no type
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp: In function `int
main()':
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:15: error: `a' cannot
appear in a constant-expression
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:15: error: template
argument 1 is invalid
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:15: error: invalid type
in declaration before ';' token
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:16: error: `my_print' is
not a type
C:\Users\bharath\Desktop\temp_cpp\kjdshf.cpp:16: error: request for
member of non-aggregate type before '(' token
I'm using Dev C++ compiler on Windows OS.
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]