Topic: Templates and Kits


Author: porter@shell.com
Date: Fri, 29 Jul 1994 22:17:49 GMT
Raw View
I can't find a mention of this in the ARM, and I haven't read anything
about it here, so ...


Has there been any discussion about being able to parameterize (via
templates) member functions of classes instead of the entire class?

It seems that this could be beneficial when using object kits
(ie. Fresco).  This example should illustrate my point:

______________________________________________________________________

template<class T>
class Goo {
    T val;
    friend class Builder;
    Goo() {}
public:

};

class Builder {
public:
    template<class T>  Goo<T>* goo() { return new Goo<T>; }
};


int
main(){
    Builder f;
    Goo<int>* g = f.goo<int>;
    Goo<float>* h = f.goo<float>;
    return 0;
}

______________________________________________________________________


Any pointers or discussion?



Thanks,
Brad
--
Brad Porter
Contract Programmer with BluWare for Shell Development Co.
(porter@shell.com)




Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Sat, 30 Jul 1994 04:48:03 GMT
Raw View
porter@shell.com writes:

>Has there been any discussion about being able to parameterize (via
>templates) member functions of classes instead of the entire class?

Yes.  The C++ committee recently voted to allow this extension
(for *non-virtual* members), and it's allowed by their latest
draft working paper.  I don't know if there are any compilers
which implement this yet.

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




Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sat, 30 Jul 1994 16:02:44 GMT
Raw View
In article <Ctq39q.7H9@shellgate.shell.com> porter@shell.com writes:
>
>Has there been any discussion about being able to parameterize (via
>templates) member functions of classes instead of the entire class?

 Accepted. They're called member templates.
>
>class Builder {
>public:
>    template<class T>  Goo<T>* goo() { return new Goo<T>; }
>};

 Spot on. That legal now.

 Builder b;
 b->goo<int>(); // fine!!

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
 Maxtal Pty Ltd,
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21
        NSW 2037, AUSTRALIA     Phone: 61-2-566-2189