|
-
September 30th, 2005, 01:02 PM
#1
Template parameters and arguments
I have several questions while reading "C++ Templates: The Complete Guide/David Vandevoorde, Nicolai M. Josuttis"
Code:
template<int I> void f(int (&)[24/(4+I)]);
int main()
{
&f<4>;
}
1. What is that type: int(&)[3] ? is it reference to a fix sized array of 3 integers?
2. what is the meaning/result of the statement in main
and how do I call function f (assuming I'd add an implementation to the template fuction decleration)
I failed to compile it on Dev-cpp 4.9.9.2 : gcc 3.4.2
though succeded with Comeau 4.3.3 online compiler -
which leads me to another question - what is a recommended C++ compiler
that supports the most of templates features?
**** **** **** **** **/**
-
September 30th, 2005, 02:16 PM
#2
Re: Template parameters and arguments
 Originally Posted by Guysl
Code:
template<int I> void f(int (&)[24/(4+I)]);
int main()
{
&f<4>;
}
1. What is that type: int(&)[3] ? is it reference to a fix sized array of 3 integers?
2. what is the meaning/result of the statement in main
and how do I call function f (assuming I'd add an implementation to the template fuction decleration)
1. No idea.
2. It takes the address of an instance of the template function, thus forcing the compiler to create a function f that takes an int(&)[3] as argument.
I failed to compile it on Dev-cpp 4.9.9.2 : gcc 3.4.2
though succeded with Comeau 4.3.3 online compiler -
which leads me to another question - what is a recommended C++ compiler
that supports the most of templates features?
Comeau is afaik known to be the compiler closest to the C++ standard.
-
September 30th, 2005, 04:43 PM
#3
Re: Template parameters and arguments
Seems the authors failed to express an useful example of language features.
-
September 30th, 2005, 04:59 PM
#4
Re: Template parameters and arguments
when compiled with Comeau's online compiler, got this message
Code:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++
"ComeauTest.c", line 5: warning: expression has no effect
&f<4>;
^
-
September 30th, 2005, 05:17 PM
#5
Re: Template parameters and arguments
 Originally Posted by Guysl
1. What is that type: int(&)[3] ? is it reference to a fix sized array of 3 integers?
Yes, it is a reference to a an array of 3 integers.
 Originally Posted by Guysl
2. what is the meaning/result of the statement in main
Basically, it has no effects.
It is the expression of the address of a template instance of the template function f.
This template instance has the I parameter equal to int.
"inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
Club of lovers of the C++ typecasts cute syntax: Only recorded member.
Out of memory happens! Handle it properly!
Say no to g_new()!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|