Topic: templates for methods...


Author: miket@world.std.com (Michael Trachtman)
Date: Fri, 25 Mar 1994 13:57:22 GMT
Raw View
John Max Skaller (maxtal@physics.su.OZ.AU) wrote:
: In article <Cn151w.IC8@world.std.com> miket@world.std.com (Michael Trachtman) writes:
: >Is something like the following supposed to work in C++.
: >
: >If not, why not ??
: >//-------------------------------------------------
: >#include <iostream.h>
: >
: >class Obj {
: >  public:
: >    // The following is the non-legal construct.
: >    // Why was it not allowed.
: >    // It would seem useful for when you write a meta handler
: >    // like a data base or operating system.
: >    template <class X> void do_something(X& x) { x.do_it(); }
: >};
: >

:  Proposed by Bjarne first. Accepted at San Diego about
:  two weeks ago. Called "member templates".

: --

Inquiring minds want to know:

1. Will this work with virtual functions too ?

class Obj {
  public:
  // pure virtual
  template <class X> virtual void do_something(X& x) = 0;
  // virtual
  template <class X> virtual void do_something_else(X& x) = { x.do_it(); };
};

If so, do implementors need special linkers that can put the vtable
together, depending on which specific template instances have been
expended by at least one of the source files ?

If so, does this not go against the "tradition" of C++, that we
want to work with old obsolete linkers. (e.g. the decision about
how to initialize static class members) ? Or has this old goal gone away ?
-------------------

2. Will this work for a template class nested inside another class ?

--------------------------

3. Would a member of the comittee be willing to post decisions that are made
   by the comitte, so that inquiring minds like ours can keep up with the
   latest gossip. (mm, I mean um... decision.)


Thanx....
Michael Trachtman




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 26 Mar 1994 15:45:54 GMT
Raw View
maxtal@physics.su.OZ.AU (John Max Skaller) writes:

>miket@world.std.com (Michael Trachtman) writes:
>>Is something like the following supposed to work in C++.
[...]
>>class Obj {
>>  public:
>>    template <class X> void do_something(X& x) { x.do_it(); }
>>};
>
> Proposed by Bjarne first. Accepted at San Diego about
> two weeks ago. Called "member templates".

In other words, yes, it's now supposed to work, but
of course it will still be a while before compilers
implement it.

>>If not, why not ??

To make life easier for compiler implementors.

Next question: will we be allowed to have templates within templates?

 template <class T>
 class Obj {
     T t;
   public:
     template <class X> void do_something(X& x) { x.do_it(t); }
 };

--
Fergus Henderson - fjh@munta.cs.mu.oz.au




Author: miket@world.std.com (Michael Trachtman)
Date: Mon, 21 Mar 1994 19:34:41 GMT
Raw View
Is something like the following supposed to work in C++.

If not, why not ??
//-------------------------------------------------
#include <iostream.h>

class Obj {
  public:
    // The following is the non-legal construct.
    // Why was it not allowed.
    // It would seem useful for when you write a meta handler
    // like a data base or operating system.
    template <class X> void do_something(X& x) { x.do_it(); }
};

class A {
  public: void do_it() { cout << "hello there\n"; }
};

void main() {
  Obj o1; A a;
  o1.do_something(a);
}
//-----------------------------------------------------


I am curious about the reasoning of why this is not allowed.


Michael Trachtman




Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 22 Mar 1994 14:34:10 GMT
Raw View
In article <Cn151w.IC8@world.std.com> miket@world.std.com (Michael Trachtman) writes:
>Is something like the following supposed to work in C++.
>
>If not, why not ??
>//-------------------------------------------------
>#include <iostream.h>
>
>class Obj {
>  public:
>    // The following is the non-legal construct.
>    // Why was it not allowed.
>    // It would seem useful for when you write a meta handler
>    // like a data base or operating system.
>    template <class X> void do_something(X& x) { x.do_it(); }
>};
>

 Proposed by Bjarne first. Accepted at San Diego about
 two weeks ago. Called "member templates".

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,      CSERVE:10236.1703
        6 MacKay St ASHFIELD,     Mem: SA IT/9/22,SC22/WG21
        NSW 2131, AUSTRALIA