* yet another template instantiation problem (w/ short snapshot :)
@ 1997-10-30 9:05 Max Lawson
1997-10-30 13:13 ` Alexandre Oliva
0 siblings, 1 reply; 3+ messages in thread
From: Max Lawson @ 1997-10-30 9:05 UTC (permalink / raw)
To: egcs-bugs; +Cc: egcs
Hi !
The following program doesn't compile with egcs-971023 on a
i586-pc-linux-glibc1 box (libc5.4.39; boot_cflags="-g -O2")
Here's the source file:
----------------z.cc-----------------------------------------------
#include <iostream.h>
template<class O, class T>
class mu_mem_fun_mvars
{
private:
O *obj_;
T (O::*m_func_)(const T&);
public:
// constructor
explicit mu_mem_fun_mvars(O& obj, T (O::*m_func)(const T&))
: obj_(&obj), m_func_(m_func)
{ }
// evaluation of the integrand at the "current" point v
T operator() ( const T& v ) { return (obj_->*m_func)(v); }
};
struct foo
{
double f(const double& t) { return 2*t; }
};
foo ff;
template<class F, class T>
T bar( F& z) { return z(1.0); }
int main()
{
cout << bar(mu_mem_fun_mvars(ff,&foo::f)) << endl;
return 0;
}
--------------------------------------------------
and the compilation results:
g++ -Wall -g -O6 z.cc
z.cc: In function `int main()':
z.cc:38: warning: implicit declaration of function `int mu_mem_fun_mvars(...)'
z.cc:38: warning: cannot pass objects of type `double (foo::*)(const double &)' through `...'
z.cc:38: incomplete type unification
z.cc:38: no matching function for call to `bar (int)'
=> Could sbdy explain me why the call to the class "mu_mem_fun_mvars"
constructor isn't handled the right way ?
This behaviour, IMHO, in a larger source make cc1plus have a fatal signal 11 :(
Thanx in advance, Max
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: yet another template instantiation problem (w/ short snapshot :)
1997-10-30 9:05 yet another template instantiation problem (w/ short snapshot :) Max Lawson
@ 1997-10-30 13:13 ` Alexandre Oliva
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 1997-10-30 13:13 UTC (permalink / raw)
To: Max Lawson; +Cc: egcs-bugs, egcs
Max Lawson writes:
> The following program doesn't compile with egcs-971023 on a
> i586-pc-linux-glibc1 box (libc5.4.39; boot_cflags="-g -O2")
egcs is correct.
> template<class O, class T>
> class mu_mem_fun_mvars
This declares a class, but then you use it as a function:
> cout << bar(mu_mem_fun_mvars(ff,&foo::f)) << endl;
> => Could sbdy explain me why the call to the class "mu_mem_fun_mvars"
> constructor isn't handled the right way ?
There's no such thing as a call to a constructor, since there's no
class named mu_mem_fun_mvars. You could achieve the desired effect by
defining a template function:
template<class O, class T>
mu_mem_fun_mvars<O,T> mu_mem_fun_mvars_f(O& obj, T (O::*m_func)(const T&)) {
return mu_mem_fun_mvars<O,T>(obj, m_func);
}
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: yet another template instantiation problem (w/ short snapshot :)
@ 1997-10-31 0:59 Max Lawson
0 siblings, 0 replies; 3+ messages in thread
From: Max Lawson @ 1997-10-31 0:59 UTC (permalink / raw)
To: oliva; +Cc: egcs-bugs, egcs
shame on me !
Seems I'm used to forget what template means :)
Thanx a lot, Max
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1997-10-31 0:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-30 9:05 yet another template instantiation problem (w/ short snapshot :) Max Lawson
1997-10-30 13:13 ` Alexandre Oliva
1997-10-31 0:59 Max Lawson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).