Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > doubt on non-ty...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 9437 of 9971
Post > Topic >>

doubt on non-type template-parameter

by Bharath <tiromarch08@[EMAIL PROTECTED] > Mar 30, 2008 at 09:40 AM

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! ]
 




 2 Posts in Topic:
doubt on non-type template-parameter
Bharath <tiromarch08@[  2008-03-30 09:40:24 
Re: doubt on non-type template-parameter
=?ISO-8859-1?Q?Daniel_Kr=  2008-03-30 13:47:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:53:36 CDT 2008.