Topic: template classes, functions and default args
Author: Miljenko Cvjetko <cvjetko@rt05.e-technik.uni-erlangen.de>
Date: 1998/02/04 Raw View
{ Please note that there are two moderated groups in the list,
and make your followups to an appropriate subset of the
listed groups. -jep clc++m }
/*
newsgroups : comp.lang.c++ comp.lang.c++.moderated gnu.g++.bug
gnu.g++.help comp.std.c++
Hi there!
I have some, probably stupid, questions regarding template
classes and functions with default arguments and non template classes.
Suppose we have one template class like
*/
# include <iostream.h>
template <class Type=int>
Type foo(Type t)
{
return t;
};
template <class Type=int>
class Bar
{
Type t_;
public:
void output();
};
//typedef Bar<int> Bar;
//class Bar : public Bar<int> ;
int main()
{
/*
CASE 1:
*/
cout << foo<double>(1.000) << endl;
/*
CASE 2: function temlpate default arguments used. **note with and
without <>**
*/
cout << foo(1) << endl;
cout << foo<>(1) << endl;
/*
CASE 3:
*/
Bar<double> bd_;
Bar<int> bi_1_;
/*
CASE 3:
*/
Bar<> bi_2_;
/*
CASE 4:
*/
Bar bi_3_;
/*
g++ egcs-1.0.1 **note without <>** is not accepted
doesn't compile complains:
template_and_nontemplate_classes_.cpp: In function `int main()':
template_and_nontemplate_classes_.cpp:65: `Bar' undeclared (first use this function)
template_and_nontemplate_classes_.cpp:65: (Each undeclared identifier is reported only once
template_and_nontemplate_classes_.cpp:65: for each function it appears in.)
template_and_nontemplate_classes_.cpp:65: parse error before `;'
*/
return 0;
}
/*
Question:
Is difference between template class inst. with default args
Bar and Bar<>
opposite to template fnc with default args
foo and foo<>
made on purpose or...?
If there is difference between Bar and Bar<> then one should be able to
declare and define the **nontemplate** class with the same name, or is it
an bug or feature in g++, or am I misunderstanding the templates and
arguments?
Pls help and thanx in advance.
Thanx
miljenko
*/
[ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
[ about comp.lang.c++.moderated. First time posters: do this! ]
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]